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

Overriding non-enumeration attributes in Enum subclass fails #12132

Closed
flaeppe opened this issue Feb 5, 2022 · 2 comments · Fixed by #12138
Closed

Overriding non-enumeration attributes in Enum subclass fails #12132

flaeppe opened this issue Feb 5, 2022 · 2 comments · Fixed by #12138
Labels
bug mypy got something wrong topic-enum

Comments

@flaeppe
Copy link
Contributor

flaeppe commented Feb 5, 2022

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:

@sobolevn
Copy link
Member

sobolevn commented Feb 5, 2022

@flaeppe are you interested in working on this? 🙂

@flaeppe
Copy link
Contributor Author

flaeppe commented Feb 6, 2022

I could take a swing at it if I find some time, though I'm not too familiar with mypy code so I'm not sure what'll come out of it.

If someone else feels like working on it, please go ahead

JukkaL pushed a commit that referenced this issue Mar 22, 2022
Allows any dunder (`__name__`) attributes except `__members__` (due to it being 
read-only) to be overridden in enum subclasses.

Fixes #12132.
JukkaL pushed a commit that referenced this issue Mar 22, 2022
Allows any dunder (`__name__`) attributes except `__members__` (due to it being 
read-only) to be overridden in enum subclasses.

Fixes #12132.
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

Successfully merging a pull request may close this issue.

2 participants