You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enum creation from values fails for certain values. #116040
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).
fromenumimportEnumclassCardinal(Enum):
RIGHT= (1, 0)
UP= (0, 1)
LEFT= (-1, 0)
DOWN= (0, -1)
def__init__(self, x: int, y: int, /) ->None:
self.x=xself.y=yup=Cardinal(0, 1) # worksright=Cardinal(1, 0) # ValueError: 1 is not a valid Cardinalright_=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.
Activity
hugovk commentedon Feb 28, 2024
Reproducible with the latest 3.13 alpha (3.13.0a4).
(3.11.8 gives
TypeError: <enum 0> cannot extend <enum 'Cardinal'>forup = Cardinal(0, 1) # works)ethanfurman commentedon Feb 28, 2024
In 3.11 you still have to use tuples; i.e.
Cardinal((0, 1))-- not having to use a tuple is a 3.12 enhancement.gh-116040: [Enum] fix by-value calls when second value is falsey; e.g…
pythongh-116040: [Enum] fix by-value calls when second value is false…
[3.12] gh-116040: [Enum] fix by-value calls when second value is fals…
gh-116040: [Enum] fix test_empty_names test (GH-116508)
pythongh-116040: [Enum] fix test_empty_names test (pythonGH-116508)
[3.12] gh-116040: [Enum] fix test_empty_names test (GH-116508) (GH-11…
pythongh-116040: [Enum] fix by-value calls when second value is false…
pythongh-116040: [Enum] fix test_empty_names test (pythonGH-116508)
pythongh-116040: [Enum] fix by-value calls when second value is false…
pythongh-116040: [Enum] fix test_empty_names test (pythonGH-116508)
fix: adjust DistinctFlag.__call__ for python 3.12.3+ compatibility
fix: adjust DistinctFlag.__call__ for python 3.12.3+
fix: adjust DistinctFlag.__call__ for python 3.12.3+ (#1659)