Open tamuhey opened 3 years ago
I think I just found a closely related example:
from typing import Literal
dest: Literal["tata", "tutu"]
for src in "tata", "tutu":
dest = src # error: Incompatible types in assignment (expression has type "str", variable has type "Literal['http', 'https']")
Don't mind me, I opened a specific issue for my example as it's not exactly the same thing (#12446).
Feature
Infer
str
is an instance of Literal based on code path:Mypy reports error for the above code, but
x
is actually an instance ofLiteral["a", "b"]
, because all values other than"a"
or"b"
raises ValueError. Pyright, one of type checkers, can infer this code has no problem.