Steven D'Aprano <steve+pyt...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue35712>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to