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 -- firstname.lastname@example.org
To unsubscribe send an email to email@example.com
Message archived at https://firstname.lastname@example.org/message/K2P4ZWF6FIRPCRKUH7IHZHMC7E3HVJER/
Code of Conduct: http://python.org/psf/codeofconduct/