false "Attempted to reuse member name in Enum definition"
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Enum and plain-class reproducer against mypy 1.8.0, then trace the Enum member-name checking path responsible for the duplicate-name diagnostic. Done means the conditional Enum definition produces no mypy errors while duplicate members in genuinely conflicting definitions remain diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100