30.06.20 18:58, Joao S. O. Bueno пише:
I ended up writting an __eq__ - and in the process I found it is not
_that_ straightforward due
to having to check subclasses types when comparing.
(given Base sequence A, child class B(A), class C(A) and class B1(B) -
Instances of B and B1 can be
equal, but instances of B and C should always be different) - or in
Python, inside __eq__ :
if not issubclass(type(other), type(self)) and not
issubclass(type(self), type(other)):
return False
It would be more correct to return NotImplemented.
Also, it is enough to test isinstance(other, type(self)) because
other.__eq__(self) be called first if the type of other is a subclass of
the type of self.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/K2P4ZWF6FIRPCRKUH7IHZHMC7E3HVJER/
Code of Conduct: http://python.org/psf/codeofconduct/