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

3.11.1: NamedTuple as Enum member converts it to an ordinary tuple. #100149

Closed
justmars opened this issue Dec 9, 2022 · 3 comments
Closed

3.11.1: NamedTuple as Enum member converts it to an ordinary tuple. #100149

justmars opened this issue Dec 9, 2022 · 3 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@justmars
Copy link

justmars commented Dec 9, 2022

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
3

Your environment

  • CPython versions tested on: 3.11.0, 3.11.1
  • Operating system and architecture: M1
@justmars justmars added the type-bug An unexpected behavior, bug, or error label Dec 9, 2022
@AlexWaygood
Copy link
Member

Duplicate of #100098

@AlexWaygood AlexWaygood marked this as a duplicate of #100098 Dec 9, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2022
@AlexWaygood
Copy link
Member

AlexWaygood commented Dec 9, 2022

It'll be fixed in 3.11.2 (cc. @ethanfurman)

@AlexWaygood AlexWaygood added stdlib Python modules in the Lib dir 3.11 only security fixes labels Dec 9, 2022
@ethanfurman
Copy link
Member

Check the duplicate for possible work-arounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only 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