-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed as not planned
Closed as not planned
Copy link
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
When using a NamedTuple as an Enum member, it converts the NamedTuple to an ordinary tuple, preventing the use of named attributes.
Consider the following base example that will be used to highlight the difference of the code under 3.11.0 and 3.11.1:
from typing import NamedTuple
from enum import Enum
class Desc(NamedTuple): # sample named tuple
label: str
num: int
class Publisher(Enum): # same enum
A = Desc(label='bob', num=1)
B = Desc(label='jane', num=2)In 3.11.0, this works fine:
>>> Publisher.A.value.label
'bob'In 3.11.1, the following error occurs:
>>> Publisher.A.value.label
AttributeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 Publishers.A.value.label
AttributeError: 'tuple' object has no attribute 'label'Interestingly, the named tuple works fine by itself:
>>> summer = Desc(label='summer', num=3)
>>> summer.num
3Your environment
- CPython versions tested on: 3.11.0, 3.11.1
- Operating system and architecture: M1
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

