[1.12, 1.13] Regression in enum narrowing #18029
Labels
bug
mypy got something wrong
topic-enum
topic-literal-types
topic-type-narrowing
Conditional type narrowing / binder
topic-union-types
Bug Report
Regression in 1.12.
Try to narrowing union between StrEnum (or IntEnum) and Literal no longer works since mypy 1.12.0
To Reproduce
Issue can be reproduce with this code sample
playground link
failing test can be found here
Expected Behavior
After the if branch return, variable type should be narrowed to Foo and mypy should not produce error
Actual Behavior
After the if branch return, variable type is considered as "Union[Foo, Literal['foo']]" and my
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: