Are all objects in Python equality-comparable? I know that you can delete __hash__ to make an object unhashable (e.g., dicts). If so, this is a great addition.
On Saturday, July 4, 2020 at 5:26:45 PM UTC-4, Joao S. O. Bueno wrote:
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.)