Closed
Description
Bug report
Bug description:
Hello,
I tried to define an enum with custom initializer and tuple values, akin to the Planet example.
When instantiating this enum from values it works for some values (0, 1) but fails for others (1, 0).
from enum import Enum
class Cardinal(Enum):
RIGHT = (1, 0)
UP = (0, 1)
LEFT = (-1, 0)
DOWN = (0, -1)
def __init__(self, x: int, y: int, /) -> None:
self.x = x
self.y = y
up = Cardinal(0, 1) # works
right = Cardinal(1, 0) # ValueError: 1 is not a valid Cardinal
right_ = Cardinal((1, 0)) # works
I'm not quite sure if I'm allowed to construct this enum from separate x and y parameters or if I need to pass a tuple.
Either way, it should either work for both (up and right) cases or fail for both cases.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
- gh-116040: [Enum] fix by-value calls when second value is falsey; e.g. Cardinal(1, 0) #116072
- [3.12] gh-116040: [Enum] fix by-value calls when second value is falsey (GH-116072) #116476
- gh-116040: [Enum] fix test_empty_names test #116508
- [3.12] gh-116040: [Enum] fix test_empty_names test (GH-116508) #116619
Activity