Wrong comparison-overlap
with Enum
/Literal
when using globals
#19283
Labels
comparison-overlap
with Enum
/Literal
when using globals
#19283
Bug Report
mypy
incorrectly reports acomparison-overlap
error when usingEnum
orLiteral
types with global variables. It seemsmypy
is not able to correctly infer that the variables are global and their types can change, leading to incorrect narrowing and subsequent overlap errors. This behavior is not observed with other type unions likeint | str
.To Reproduce
Expected Behavior
Mypy should not report any
comparison-overlap
errors in the provided code when run with--strict
. It should understand thatl
ande
are global variables and their types can be reassigned within thef()
function, so the assertions and print statements ing()
are valid comparisons afterf()
is called.Actual Behavior
The following errors are reported:
Your Environment
--strict
mypy.ini
(and other config files): No configuration file used.The text was updated successfully, but these errors were encountered: