Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3k
Support attribute access on enum members correctly#19422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Support attribute access on enum members correctly#19422
Conversation
@@ -1971,8 +1972,8 @@ class B2(A2): # E: Cannot extend enum with existing members: "A2" | |||
class A3(Enum): | |||
x: Final[int] # type: ignore | |||
class B3(A3): | |||
x = 1 # E: Cannot override final attribute "x" (previously declared in base class "A3") | |||
x = 1 # E: Cannot override final attribute "x" (previously declared in base class "A3") \ |
sterliakovJul 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Note that this (and other equivalent) change is correct: as per thespec, unannotated attrs should be interpreted as nonmembers, so, strictly speaking, you're assigning a soon-to-become enum instance to something of typeint
, breaking the interface. And it doesn't matter much as there is already another diagnostic on this line.
According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks, looks reasonable! Not a full review, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good to me, but I'm probably not the best expert on enum semantics. Let's keep this open for a while in case somebody else would have a detailed look. Nice to see this fix so many issues!
Uh oh!
There was an error while loading.Please reload this page.
Fixes#11368 (apparently canonical).
Fixes#10910.
Fixes#12107.
Fixes#13841.
Fixes#15186.
Fixes#15454.
Fixes#19418.
mypy
now understands attribute access on enum members - the "recursive" behaviour of supporting access of almost-all enum members from members. "Almost", because.name
and.value
take precedence even if a member of the same name exists.Looks like this is a much wanted feature.