Skip to content

Enum creation from values fails for certain values. #116040

Closed
@maflAT

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

3.12bugs and security fixes3.13bugs and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions