[issue35712] Make NotImplemented unusable in boolean context
Steven D'Aprano
report at bugs.python.org
Thu Jan 10 20:44:01 EST 2019
Steven D'Aprano <steve+python at pearwood.info> added the comment:
> the canonical __ne__ delegation to __eq__ for any class should be implemented as something like
I disagree that your code snippet is the canonical way to write __ne__. I'd write it like this:
def __ne__(self, other):
return not (self == other)
Or just not write it at all. Python will automatically call __eq__ going back to Python 2.4 (and possibly older).
Delegating to __eq__ directly is the wrong way to do it.
> NotImplemented is a sentinel value that should never be evaluated in a boolean context
I don't see why not. I can't think of any use-cases where I would want to *specifically* use NotImplemented in a boolean context, but I see no good reason why I would want it to fail if one happened to do so.
----------
nosy: +steven.daprano
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35712>
_______________________________________
More information about the Python-bugs-list
mailing list