Skip to content

Conversation

@sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Sep 1, 2025

Fixes #18345.
Fixes #16558.

See the linked ticket for reasoning - enums with members are implicitly final and should be treated exactly as if they were decorated with @final.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2025

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

@ilevkivskyi ilevkivskyi merged commit 341d3cc into python:master Sep 2, 2025
20 checks passed
self.fail("Self type cannot be used in a metaclass", t)
if self.api.type.self_type is not None:
if self.api.type.is_final:
if self.api.type.is_final or self.api.type.is_enum and self.api.type.enum_members:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should enums have is_final set maybe, so they opt into all behaviors like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about this. We can try this in a separate PR (this may also simplify a bit some of the mypyc code related to final enums).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use typing.Self with Enums Self type isn't considered to be the same as the explicit class type

3 participants