Skip to content

Overriding non-enumeration attributes in Enum subclass fails #12132

@flaeppe

Description

@flaeppe

Bug Report

Inheriting an Enum-class and overriding, for example, a dunder-attribute fails to typecheck. Although it works fine during runtime.

To Reproduce

from enum import Enum


class BaseEnum(Enum):
    __something__ = 3


class SomeEnum(BaseEnum):
    __something__ = 2

Expected Behavior

It should typecheck, as it passes during runtime.

Actual Behavior

error: Cannot override final attribute "__something__" (previously declared in base class "BaseEnum")

Your Environment

  • Mypy version used: master (26fdd45)
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files):
strict_optional = True
  • Python version used: 3.9.4
  • Operating system and version: MacOS Catalina 10.15.6

The issue has also been briefly mentioned in these places:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions