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

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

Open
sterliakov wants to merge2 commits intopython:master
base:master
Choose a base branch
Loading
fromsterliakov:bugfix/gh-19418-enum-nonmember-on-instance

Conversation

sterliakov
Copy link
Collaborator

@sterliakovsterliakov commentedJul 11, 2025
edited
Loading

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.

fromenumimportEnumclassE(Enum):FOO=1BAR=1# The following is still a `E.BAR` instance:E.FOO.FOO.BAR.BAR

Looks like this is a much wanted feature.

@@ -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") \
Copy link
CollaboratorAuthor

@sterliakovsterliakovJul 11, 2025
edited
Loading

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.

@sterliakovsterliakov marked this pull request as ready for reviewJuly 11, 2025 00:58
@github-actionsGitHub Actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Member

@sobolevnsobolevn left a 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.

sterliakov reacted with heart emoji
Copy link
Collaborator

@JukkaLJukkaL left a 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!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

[8]ページ先頭

©2009-2025 Movatter.jp