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

Change in semantics and much worse performance for enum members. #93910

Closed
Assignees
ethanfurman
Labels
performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory
@markshannon

Description

@markshannon

Given the enum:

classColours(Enum):RED=1

In Python 3.9 and 3.10:

>>>Colours.__dict__["RED"]isColours.REDTrue>>>Colours.RED.RED<Colours.RED:1>

In Python 3.11:

>>>Colours.__dict__["RED"]isColours.REDFalse>>>Colours.RED.REDTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>File"/home/mark/repos/cpython/Lib/enum.py",line198,in__get__raiseAttributeError(^^^^^^^^^^^^^^^^^^^^^AttributeError:<enum'Colours'>memberhasnoattribute'RED'

While these might seem like minor semantic changes, there is also a large performance impact.
Lookup ofColours.RED is simple and efficient in 3.10, but involves a lot of indirection and dispatching through theenum.property class in 3.11.
The performance impact is likely to get worse in 3.12, as we optimize more kinds of attributes.

Introduced inc314e60, I believe.

@pablogsal
@ethanfurman

Linked PRs

Metadata

Metadata

Assignees

Labels

performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

Projects

Status

Done

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2026 Movatter.jp