You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Enum] Deprecate member.member access with removal in 3.14 #95077
Accessing one enum member from another was originally forbidden, but added later to improve performance (but still warned against in the docs). Those performance issues are no longer a problem, and it is now possible to have deprecation warnings in the code to aid in transitioning away from such usage.
The 3.12 timings are with every enum member being accessed via the enum.property descriptor (i.e. no enum members being stored directly in the enum class __dict__).
Out of curiosity I ran the above code with member.member access, both with and without the deprecation warning:
warning
no warning
20.41
4.16
So updating code to be correct will keep performance to 3.11 levels (or better).
As somebody who hasn't been following enum changes very closely: why is this?
I can only imagine it's due to the work you and others have done. I had already noticed this in the other issue when comparing 3.10/3.11/3.12, and I was able to get another slight boost by storing the member directly in the descriptor and avoiding a dict lookup.
I can make .name and .value normal properties (when no member by the same name exists), but when I tried that they stopped being reported by inspect and so also stopped showing up in pydoc.
Activity
brandtbucher commentedon Jul 21, 2022
As somebody who hasn't been following
enumchanges very closely: why is this?ethanfurman commentedon Jul 21, 2022
Performance timings on my system:
The code
The 3.12 timings are with every enum member being accessed via the
enum.propertydescriptor (i.e. no enum members being stored directly in the enum class__dict__).Out of curiosity I ran the above code with
member.memberaccess, both with and without the deprecation warning:So updating code to be correct will keep performance to 3.11 levels (or better).
JelleZijlstra commentedon Jul 21, 2022
How are the timings for accessing
Color.RED.valueaffected?ethanfurman commentedon Jul 21, 2022
I can only imagine it's due to the work you and others have done. I had already noticed this in the other issue when comparing 3.10/3.11/3.12, and I was able to get another slight boost by storing the member directly in the descriptor and avoiding a dict lookup.
ethanfurman commentedon Jul 21, 2022
Some improvement, but I don't think I can take any credit for that (and those timings are not affected by this issue).
ethanfurman commentedon Jul 21, 2022
I can make
.nameand.valuenormal properties (when no member by the same name exists), but when I tried that they stopped being reported byinspectand so also stopped showing up inpydoc.gh-95077: [Enum] add code-based deprecation warnings for member.membe…