I need to make a custom comparison between objects during a restricted scope, is there any way to do that and without polluting the operator, eg restore the previous eq afterwards ?
class Test():
def __eq__(self, i):
print "eq lvl 1"
def test(a , b):
def _itest(i):
print "eq lvl 2"
>>> a = Test()
>>> b = Test()
>>> a == b
eq lvl 1
>>> test(a, b)
>>> a == b
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: _itest() takes exactly 1 argument (2 given)
I'm doing so because given certain condition I need to degrade the eq operator.
Note: I want to override __eq__ in order to use the in statement.