This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients josh.r, p-ganssle, serhiy.storchaka, veky
Date 2019-07-26.18:31:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1564165874.56.0.00459526121698.issue37685@roundup.psfhosted.org>
In-reply-to
Content
@p-ganssle: Yup. If both sides return NotImplemented, __eq__ and __ne__ return a result based on an identity comparison; all other rich comparisons raise TypeError in that case. Code is here: https://github.com/python/cpython/blob/3.7/Objects/object.c#L679

As you said, NotImplemented is never actually returned from syntax based comparisons; you only see it if you explicitly call __eq__ (and related __XX__ rich comparison methods) directly (usually because you're implementing one method in terms of another).

AFAICT, about the only time you should ever be returning False rather than NotImplemented is when the other operand is an instance of the same class as you (or a subclass), allowing you to say with certainty that you know how to do the comparison (Python already handles the edge case of subclasses for you, by calling the comparison method on the subclass first, even if it's on the right hand side). In any other case, you return NotImplemented, and let the other side determine if they know how to do the comparison.
History
Date User Action Args
2019-07-26 18:31:14josh.rsetrecipients: + josh.r, serhiy.storchaka, veky, p-ganssle
2019-07-26 18:31:14josh.rsetmessageid: <1564165874.56.0.00459526121698.issue37685@roundup.psfhosted.org>
2019-07-26 18:31:14josh.rlinkissue37685 messages
2019-07-26 18:31:14josh.rcreate