Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checker.is_final_enum_value duplicates TypoInfo.enum_members logic #18565

Open
sobolevn opened this issue Jan 29, 2025 · 0 comments
Open

Checker.is_final_enum_value duplicates TypoInfo.enum_members logic #18565

sobolevn opened this issue Jan 29, 2025 · 0 comments
Assignees
Labels
bug mypy got something wrong topic-enum

Comments

@sobolevn
Copy link
Member

After merging #18559 I think it would make sense to change how we check for @final enums here:

mypy/mypy/checker.py

Lines 2705 to 2727 in d4e7a81

def is_final_enum_value(self, sym: SymbolTableNode) -> bool:
if isinstance(sym.node, (FuncBase, Decorator)):
return False # A method is fine
if not isinstance(sym.node, Var):
return True # Can be a class or anything else
# Now, only `Var` is left, we need to check:
# 1. Private name like in `__prop = 1`
# 2. Dunder name like `__hash__ = some_hasher`
# 3. Sunder name like `_order_ = 'a, b, c'`
# 4. If it is a method / descriptor like in `method = classmethod(func)`
if (
is_private(sym.node.name)
or is_dunder(sym.node.name)
or is_sunder(sym.node.name)
# TODO: make sure that `x = @class/staticmethod(func)`
# and `x = property(prop)` both work correctly.
# Now they are incorrectly counted as enum members.
or isinstance(get_proper_type(sym.node.type), FunctionLike)
):
return False
return self.is_stub or sym.node.has_explicit_value

There's no need to duplicate the .enum_member logic here once again. I will refactor this piece.

@sobolevn sobolevn added bug mypy got something wrong topic-enum labels Jan 29, 2025
@sobolevn sobolevn self-assigned this Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-enum
Projects
None yet
Development

No branches or pull requests

1 participant