Is it possible to overload operators for Python functions? I have a bunch of functions taking two positional arguments and returning boolean type, e.g.
def both_positive(a, b):
return a > 0 and b > 0
def larger(a, b):
return a > b
def both_negative(a, b):
return a < 0 and b < 0
# ... many other similar functions
func = both_positive & larger # means logical and
# func = both_positive | larger # means logical or
# complex_customized_logic = both_positive | larger & either_float ...
assert func(3, 1) is True # 3 > 1, and both positive
assert func(2, -1) is False # 2 > -1, but -1 is negative