-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-enumtopic-literal-typestopic-type-narrowingConditional type narrowing / binderConditional type narrowing / bindertopic-union-types
Description
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
from typing_extensions import Literal
from typing import Union
from enum import StrEnum
class Foo(StrEnum):
FOO = 'a'
def foo(a: Union[Foo, Literal['foo']]) -> Foo:
if a == 'foo':
return Foo.FOO
return aplayground 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 version used: 1.12, 1.13, master
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: all versions from 3.8 to 3.13
twavv
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-enumtopic-literal-typestopic-type-narrowingConditional type narrowing / binderConditional type narrowing / bindertopic-union-types