[issue35712] Make NotImplemented unusable in boolean context
Alex Waygood
report at bugs.python.org
Mon Sep 20 11:33:49 EDT 2021
Alex Waygood <Alex.Waygood at Gmail.com> added the comment:
The following code now leads to a `DeprecationWarning`, but I am unclear why it should.
```
>>> from enum import Enum
>>>
>>> class CardColour(Enum):
... """Enumeration of the two colours in a pack of cards."""
...
... BLACK = 'black'
... RED = 'red'
...
... def other_colour(self):
... """Given one colour, get the other one."""
... return next(filter(self.__ne__, CardColour))
...
>>> CardColour.BLACK.other_colour()
<input>:5: DeprecationWarning: NotImplemented should not be used in a boolean context
<CardColour.RED: 'red'>
```
If I change the last line of `other_colour` to either `return next(colour for colour in CardColour if colour != self)` or `return next(colour for colour in CardColour if colour is not self)`, the warning goes away.
Is this intended behaviour?
----------
nosy: +AlexWaygood
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35712>
_______________________________________
More information about the Python-bugs-list
mailing list