[Python-ideas] Overloading operators for testing

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Sep 18 00:01:35 EDT 2016


Arek Bulski wrote:
> def __glob_eq__(a,b):
>   if not a == b:
>       raise FoundInequalityError(a,b)
>   return True
> 
> assert obj1 == obj2   #<-- using eq above

How would you ensure that this overriding only applied in
the places you want it? You don't want to change the meaning
of == in the code under test!

Related to that, how would you prevent the use of ==
in the definition of __glob_eq__ above from triggering infinite
recursion?

-- 
Greg


More information about the Python-ideas mailing list