7/25/2019 6:00 AM, Eric V. Smith wrote:
On 7/25/2019 4:27 AM, Kyle Stanley wrote:
Serhiy Storchaka wrote:
Is there any precedence of raising an exception in the equality
comparison?
Does 3 == "3" returning False make more sense to you?
Personally, I don't find ``3 == "3"`` to be an equivalent comparison
to ``d0.values() == d1.values()``. Generally, it makes sense when
comparing two items of different types, they are not going to be
equivalent (except in cases such as ``3 == 3.0``, but in that case
they are both subtypes of numeric).
I don't know that an exception would be the best behavior to suit this
situation (or for anything using ``__eq__`` for that matter), but
returning ``False`` seems to be a bit misleading. Instead, I think
that either returning the ``NotImplemented`` constant or ``None``
would provide far more useful information to the user, without the
hindrance of causing an exception. I'm leaning more favorably towards
``NotImplemented`` because it explicitly tells the user "Hey, that
equality comparison isn't implemented".
That makes things worse. Now the comparison is always true in a boolean
context. And presumably you'd want __ne__ to also return NotImplemented,
so then both __eq__ and __ne__ would be true, since bool(NotImplemented)
is True.
I might have to take that back. I hadn't factored in what the == and !=
machinery does, beyond calling __eq__ or __ne__.
Eric
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/C3RNFXQ75J57BD46JXUVPBGLMKAW6XOD/