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

3.11.1 Regression: namedtuple Enum values are cast to tuple #100098

Closed
Assignees
ethanfurman
Labels
type-bugAn unexpected behavior, bug, or error
@Zannick

Description

@Zannick

Bug report

Between 3.11.0 and 3.11.1, Enums whose values are namedtuple objects have their values converted to tuple, which drops the field names we expect to be able to use, causing AttributeErrors. Test cases below create a namedtuple and an enum whose values are instances of that tuple. In the 3.11.1 case, referencing the enum value likeNTEnum.NONE.value produces a tuple and not a namedtuple. In both cases,copy.copy preserves the namedtuple type.

It is not clear whether any item in the changelog or release notes references this change, nor could I quickly tell whether this was related to changes to address#93910.

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
>>>fromenumimportEnum>>>fromcollectionsimportnamedtuple>>>TTuple=namedtuple('TTuple','id a blist')>>>classNTEnum(Enum):...NONE=TTuple(0,0, [])...A=TTuple(1,2, [4])...B=TTuple(2,4, [0,1,2])... ...>>>NTEnum.NONE<NTEnum.NONE:TTuple(id=0,a=0,blist=[])>>>>NTEnum.NONE.valueTTuple(id=0,a=0,blist=[])>>> [x.valueforxinNTEnum][TTuple(id=0,a=0,blist=[]),TTuple(id=1,a=2,blist=[4]),TTuple(id=2,a=4,blist=[0,1,2])]>>>importcopy>>>x=TTuple(0,1, [7])>>>xTTuple(id=0,a=1,blist=[7])>>>copy.copy(x)TTuple(id=0,a=1,blist=[7])>>>copy.deepcopy(x)TTuple(id=0,a=1,blist=[7])>>>NTEnum.NONE.value.blist[]
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
>>>fromenumimportEnum>>>fromcollectionsimportnamedtuple>>>TTuple=namedtuple('TTuple','id a blist')>>>classNTEnum(Enum):...NONE=TTuple(0,0, [])...A=TTuple(1,2, [4])...B=TTuple(2,4, [0,1,2])... ...>>>NTEnum.NONE<NTEnum.NONE: (0,0, [])>>>>NTEnum.NONE.value(0,0, [])>>> [x.valueforxinNTEnum][(0,0, []), (1,2, [4]), (2,4, [0,1,2])]>>>importcopy>>>x=TTuple(0,1, [7])>>>xTTuple(id=0,a=1,blist=[7])>>>copy.copy(x)TTuple(id=0,a=1,blist=[7])>>>copy.deepcopy(x)TTuple(id=0,a=1,blist=[7])>>>NTEnum.NONE.value.blistTraceback (mostrecentcalllast):File"<pyshell#16>",line1,in<module>NTEnum.NONE.value.blistAttributeError:'tuple'objecthasnoattribute'blist'

Your environment

  • CPython versions tested on: 3.11.0, 3.11.1
  • Operating system and architecture: win64 (amd64)
  • 3.11.0 additionally tested on linux
  • 3.11.0, 3.11.1 tested in IDLE

Linked PRs

Metadata

Metadata

Assignees

Labels

type-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