Skip to content

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

Open
@belm0

Description

@belm0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions