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 of Colours.RED is simple and efficient in 3.10, but involves a lot of indirection and dispatching through the enum.property class in 3.11.
The performance impact is likely to get worse in 3.12, as we optimize more kinds of attributes.
Introduced in c314e60, I believe.
@pablogsal
@ethanfurman
Linked PRs
Given the enum:
In Python 3.9 and 3.10:
In Python 3.11:
While these might seem like minor semantic changes, there is also a large performance impact.
Lookup of
Colours.REDis simple and efficient in 3.10, but involves a lot of indirection and dispatching through theenum.propertyclass in 3.11.The performance impact is likely to get worse in 3.12, as we optimize more kinds of attributes.
Introduced in c314e60, I believe.
@pablogsal
@ethanfurman
Linked PRs