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

Enum final checking false positive in complex case #11702

Closed
JukkaL opened this issue Dec 10, 2021 · 3 comments
Closed

Enum final checking false positive in complex case #11702

JukkaL opened this issue Dec 10, 2021 · 3 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 10, 2021

This code generates a false positive, but weirdly I can only reproduce it if the base class is defined in a different module:

from mod import E

class EE(E):  # Cannot inherit from final class "E"
    X = (0, "")
# mod.py
from enum import Enum
from typing import Optional, Type

class E(int, Enum):
    def __init__(self, _: int, x: Optional[str] = None) -> None:
        self.x = x

    def __new__(cls: Type['E'], value: int, x: Optional[str] = None) -> 'E':
        enum = int.__new__(cls, value)
        enum._value_ = value
        enum.x = x
        return enum

The code works at runtime.

This started happening as a side effect of #11247.

Marking as high priority, since this is a regression. If it seems clear that this may only happen in pretty specialized circumstances, we can perhaps lower the priority.

cc @sobolevn

@JukkaL JukkaL added bug mypy got something wrong priority-0-high false-positive mypy gave an error on correct code labels Dec 10, 2021
@sobolevn
Copy link
Member

See https://github.com/python/mypy/pull/11579/files
Will it fix this case?

@sobolevn
Copy link
Member

Looks like it fixes this issue indeed!
Снимок экрана 2021-12-10 в 20 35 04
Снимок экрана 2021-12-10 в 20 35 20

@JukkaL
Copy link
Collaborator Author

JukkaL commented Dec 10, 2021

Excellent! I can review the PR early next week.

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

No branches or pull requests

2 participants