Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
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)