On 7/25/2019 4:19 PM, Kyle Stanley wrote:
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`? It seems like it would be useful for it to be able to return `NotImplemented` in situations such as this.
Because no one is testing for it. And just using it in a boolean context will return True.
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__()`?
"Based on", yes. If all of the options return NotImplemented, it falls back on identity comparison. I can't find this in the Python 3 docs, but it's no doubt somewhere. Eric