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

Defining _order_ in an enum class rejected #11699

Closed
JukkaL opened this issue Dec 10, 2021 · 2 comments · Fixed by #11713
Closed

Defining _order_ in an enum class rejected #11699

JukkaL opened this issue Dec 10, 2021 · 2 comments · Fixed by #11713
Labels
bug mypy got something wrong priority-0-high

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 10, 2021

This generates an error, even though it's valid:

from enum import Enum

class E(Enum):
    _order_ = 'X Y'  # Cannot override writable attribute "_order_" with a final one
    X = 1
    Y = 2

According to the docs, _order_ is a somewhat magical attribute, but it's okay to define it.

The error started happening as a side effect of #10852.

It looks like _order_ actually isn't a valid attribute at runtime, so a potential fix would be to remove it from typeshed. If we want to do this right, we should also remove an explicit definition from the TypeInfo, since it's not available at runtime.

@sobolevn What do you think?

This is a regression, so marking as high priority.

@JukkaL JukkaL added bug mypy got something wrong priority-0-high labels Dec 10, 2021
@sobolevn
Copy link
Member

sobolevn commented Dec 10, 2021

I think that Enum subclasses should be special cased for Cannot override writable attribute "_order_" with a final one rule. Because, a lot of things like

from enum import Enum

class E(Enum):
    value = 1  # E: Cannot override writable attribute "value" with a final one

print(E.value)

work just fine in runtime, but mypy is not really happy.

@sobolevn
Copy link
Member

My proposal: #11713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants