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

Type mismatch error with overlapping enums #15196

Open
LukasKrocek opened this issue May 6, 2023 · 0 comments
Open

Type mismatch error with overlapping enums #15196

LukasKrocek opened this issue May 6, 2023 · 0 comments
Labels
bug mypy got something wrong topic-enum

Comments

@LukasKrocek
Copy link

Bug Report

Enum is casted to literal when asserting its value, even when it is declared as attr of class that can be mutated after assertion

To Reproduce

from enum import Enum


class MyEnum(Enum):
    A = 1
    B = 2


class A:
    def __init__(self, enum: MyEnum):
        self.enum = enum

    def change(self) -> None:
        self.enum = MyEnum.B

if __name__ == "__main__":
    a = A(MyEnum.A)
    assert a.enum == MyEnum.A
    a.change()
    assert a.enum == MyEnum.B  

Expected Behavior

No error

Actual Behavior

Non-overlapping equality check (left operand type: "Literal[MyEnum.A]", right operand type: "Literal[MyEnum.B]")

Your Environment

  • Mypy version used: current master
  • Mypy command-line flags: --strict
  • Python version used: 3.10
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

No branches or pull requests

2 participants