-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
Feature
Infer str is an instance of Literal based on code path:
from typing import Literal
def f(x: Literal["a", "b"]):
...
def g(x: str):
if x == "a":
...
elif x == "b":
...
else:
raise ValueError()
f(x) # ERROR: "f" has incompatible type "str"; expected "Union[Literal['a'], Literal['b']]"Mypy reports error for the above code, but x is actually an instance of Literal["a", "b"], because all values other than "a" or "b" raises ValueError.
Pyright, one of type checkers, can infer this code has no problem.
Reactions are currently unavailable