25.07.19 23:19, Kyle Stanley пише:
Serhiy Storchaka wrote:
Actually, the == operator cannot return NotImplemented.
Thanks for the clarification. What is the reason for this limitation and is it
only possible for the `==` operator to return one of `None`, `False`, or `True`?
The `==` operator can return any value except NotImplemented. But all
implementations in the stdlib return only booleans. NumPy is the one
famous exception.
It seems like it would be useful for it to be able to return `NotImplemented`
in situations such as this.
It is the purpose of NotImplemented. It signals "ignore me, use other
way to evaluate a result".
Also, I think that I may have had some misconceptions with regards to the
relationship between the `__eq__()` method and the `==` operator. I know they
are not the same, but isn't the result of the `==` operator based on a
transformation of the result from `__eq__()`?
Yes, it is. And NotImplemented means that the result of `__eq__()` (or
other dunder methods) should be ignored.
As far as I can tell, the equality of two dictionary views are assessing used
[`PyObject
dictrich_compare`](https://github.com/python/cpython/blob/544fa15ea1b7b73068319bdb217b684e2fd7bacc/Objects/dictobject.c#L4040).
Wouldn't it be possible to perform a conditional check if the view on the left
side of the comparison is a values view and if so, use
`Py_RETURN_NOTIMPLEMENTED`?
How does it differ from the default implementation (`object.__eq__`)?
_______________________________________________
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/RDHMG6SD7B3WTVZDBSB2LQ347YA2X753/