Kyle Stanley wrote:
Serhiy Storchaka wrote:

Actually, the == operator cannot return NotImplemented.

What is the reason for this limitation

It's not a limitation, it's a consequence of the way the operator
machinery works. NotImplemented is used by operator methods to
signal to the interpreter that it should take some alternative
action. In this case, it will first try the other operand's
__eq__ method, and if that returns NotImplemented as well, it
assumes that the operands are not equal and returns False.

> and is
> it only possible for the `==` operator to return one of `None`, `False`, or
> `True`?

No, it's possible for == to return almost anything (numpy arrays
return an array of booleans, for example). It just happens that
NotImplemented can't be returned, because it has a special
meaning to the interpreter.

--
Greg
_______________________________________________
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/MHVPVXXMNPQV57LIMDN7VKJIPOH26OQR/

Reply via email to