Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enum: auto() is not activated if combined with other values on assignment line #93464

Closed
Assignees
ethanfurman
Labels
3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@huwcbjones

Description

@huwcbjones

Bug report

Creating a Enum that uses automatic values and tuple assignment doesn't work!

fromenumimportEnum,autofromtypingimportAnyclassDay(Enum):def__new__(cls,value,abbr=None):obj=Enum.__new__(cls,value)obj.abbr=abbrreturnobj@staticmethoddef_generate_next_value_(name:str,start:int,count:int,last_values:list[Any])->Any:returnnameMONDAY=auto(),"Mon"# etcprint(Day.MONDAY,Day.MONDAY.value,Day.MONDAY.abbr)

Run that snippet and you get

Traceback (most recent call last):  File "mwe.py", line 5, in     class Day(Enum):  File "lib/python3.9/enum.py", line 288, in __new__    enum_member = __new__(enum_class, *args)  File "mwe.py", line 8, in __new__    obj = Enum.__new__(cls, value)  File "lib/python3.9/enum.py", line 702, in __new__    raise ve_excValueError: <enum.auto object at 0x10b673fa0> is not a valid Day

Your environment

  • CPython versions tested on: 3.9.2/3.9.7/3.10.2
  • Operating system and architecture: Debian 11 (amd64)/macOS 11.4 (amd64)

Metadata

Metadata

Assignees

Labels

3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp