Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum creation from values fails for certain values. #116040

Closed
maflAT opened this issue Feb 28, 2024 · 2 comments
Closed

Enum creation from values fails for certain values. #116040

maflAT opened this issue Feb 28, 2024 · 2 comments
Assignees
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes needs backport to 3.12 bug and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@maflAT
Copy link

maflAT commented Feb 28, 2024

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

@maflAT maflAT added the type-bug An unexpected behavior, bug, or error label Feb 28, 2024
@hugovk hugovk added 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Feb 28, 2024
@hugovk
Copy link
Member

hugovk commented Feb 28, 2024

Reproducible with the latest 3.13 alpha (3.13.0a4).

(3.11.8 gives TypeError: <enum 0> cannot extend <enum 'Cardinal'> for up = Cardinal(0, 1) # works)

@ethanfurman ethanfurman self-assigned this Feb 28, 2024
@ethanfurman ethanfurman added stdlib Python modules in the Lib dir 3.11 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Feb 28, 2024
@ethanfurman ethanfurman removed 3.11 only security fixes needs backport to 3.11 only security fixes labels Feb 28, 2024
@ethanfurman
Copy link
Member

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.

ethanfurman added a commit to ethanfurman/cpython that referenced this issue Mar 7, 2024
ethanfurman added a commit that referenced this issue Mar 7, 2024
ethanfurman added a commit that referenced this issue Mar 11, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 11, 2024
* and fix _not_given usage
(cherry picked from commit 3c0dcef)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
ethanfurman added a commit that referenced this issue Mar 11, 2024
…6619)

* and fix _not_given usage

(cherry picked from commit 3c0dcef)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Scrxtchy added a commit to Scrxtchy/interactions.py that referenced this issue Apr 18, 2024
As None is a valid value now, as of 3.12.3 it cannot be used for the name
python/cpython#116040
Scrxtchy added a commit to Scrxtchy/interactions.py that referenced this issue Apr 18, 2024
As None is a valid value now, as of 3.12.3 it cannot be used
for the name python/cpython#116040
xvi-ii pushed a commit to interactions-py/interactions.py that referenced this issue Apr 20, 2024
As None is a valid value now, as of 3.12.3 it cannot be used
for the name python/cpython#116040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes needs backport to 3.12 bug and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants