Skip to content

Support _value_ as a fallback for ellipsis Enum members - #19352

Merged
JukkaL merged 9 commits into
python:masterfrom
sterliakov:feature/gh-19334-respect-enum-sunder-value
Jul 9, 2025
Merged

Support _value_ as a fallback for ellipsis Enum members#19352
JukkaL merged 9 commits into
python:masterfrom
sterliakov:feature/gh-19334-respect-enum-sunder-value

Conversation

@sterliakov

@sterliakov sterliakov commented Jun 27, 2025

Copy link
Copy Markdown
Collaborator

Fixes #19334.

This does not affect enums with explicit values different from ellipsis and is limited to enums defined in stub files.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@sterliakov
sterliakov marked this pull request as ready for review June 28, 2025 12:12
Comment thread mypy/plugins/enums.py Outdated
@github-actions

This comment has been minimized.

@A5rocks A5rocks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, a couple nitpicks.

Comment thread mypy/plugins/enums.py Outdated
Comment thread test-data/unit/check-enum.test Outdated
Comment thread test-data/unit/lib-stub/enum.pyi
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

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

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, looks good, except for a nit about cyclic import dependencies. This is good to merge as is, since the issue is pretty minor, but it would be nice you can fix it in a follow-up PR.

Comment thread mypy/plugins/enums.py

import mypy.plugin # To avoid circular imports.
from mypy.nodes import TypeInfo
from mypy.checker import TypeChecker

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a bit unfortunate that we have another circular import dependency. What about adding adding a helper method for checking whether we are type checking a stub file to the checker api? (It's okay to do this in a follow-up PR.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum types are incorrectly inferred

4 participants