[issue35712] Make NotImplemented unusable in boolean context

Serhiy Storchaka report at bugs.python.org
Mon Sep 20 12:24:36 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Interesting, it is because object().__eq__(object()) returns NotImplemented instead of False.

object.__eq__ could return False if arguments have same type (or in some other cases). I think it would not break anything, and it would fix your case. But I am not sure that it is worth to change this. Using bound methods __eq__ and __ne__ is an antipattern, and we should not encourage this, even if it is safe as in your case. If you want to discuss this more, it is better to do this on a mailing-list or Discuss.

Your code can be rewritten as:

    def other_colour(self):
        for other in CardColour:
            if self != other:
                return other
        assert False, "not reachable"

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35712>
_______________________________________


More information about the Python-bugs-list mailing list