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

false "Attempted to reuse member name in Enum definition" #16876

Open
belm0 opened this issue Feb 6, 2024 · 0 comments
Open

false "Attempted to reuse member name in Enum definition" #16876

belm0 opened this issue Feb 6, 2024 · 0 comments
Labels
bug mypy got something wrong topic-enum

Comments

@belm0
Copy link

belm0 commented Feb 6, 2024

Bug Report

When using an if/else in class scope of an Enum definition, there is a false error "Attempted to reuse member name in Enum definition".

I understand mypy might have an opinion about this pattern, but I noticed there is no equivalent issue for a plain class. So this seems to be an issue specific to Enum that could potentially be relaxed.

To Reproduce

class Foo(Enum):
    if IS_BAZ:
        DISABLED = 16
    else:
        # error: Attempted to reuse member name "DISABLED" in Enum definition "Foo"  [misc]
        DISABLED = 256

class Bar:
    if IS_BAZ:
        DISABLED = 16
    else:
        DISABLED = 256   # (no error)

Expected Behavior

no mypy errors

Actual Behavior

error: Attempted to reuse member name "DISABLED" in Enum definition "Foo"  [misc]

Your Environment

  • Mypy version used: 1.8.0
  • Python version used: 3.8
@belm0 belm0 added the bug mypy got something wrong label Feb 6, 2024
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

2 participants