-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Description
For the partially defined check (--enable-error-code partially-defined), mypy generates a false-positive in the following case:
def f1(x: int | str) -> int:
if isinstance(x, int):
y = 1
elif isinstance(x, str):
y = 2
return y # error: Name "y" may be undefinedThe same applies to match statements:
def f(x: int | str) -> int:
match x:
case int():
y = 1
case str():
y = 2
return y # error: Name "y" may be undefinedIt's likely that mypy already detects this somewhere, since it doesn't complain about the missing return:
def f3(x: int | str) -> int:
if isinstance(x, int):
return 1
elif isinstance(x, str):
return 2sjdemartini