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 commented on Jul 21, 2022
As somebody who hasn't been following enum changes very closely: why is this?
ethanfurman commented on Jul 21, 2022
Performance timings on my system:
The codeThe 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:
So updating code to be correct will keep performance to 3.11 levels (or better).
JelleZijlstra commented on Jul 21, 2022
How are the timings for accessing Color.RED.value affected?
ethanfurman commented on 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 commented on 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 commented on Jul 21, 2022
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.
gh-95077: [Enum] add code-based deprecation warnings for member.membe…