On Sat, 4 Jul 2020 at 16:51, Serhiy Storchaka
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.
Ah - yes. Half the logic is already on the __eq__ semantics - thanks. Well, I am updating that on my code right now. Anyway I am not seeing anyone opposing this going into col...abc.Sequence - Maybe it is ok for a BPO? (yes, there is this consideration I had, and also Guido, that it would create new behavior in classes that already exist, but I saw no way that could break code not specially crafted to break with this change.) _______________________________________________
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/K2P4ZW... Code of Conduct: http://python.org/psf/codeofconduct/