Closed as not planned
Description
Bug Report
I have two small similar examples for you:
1:
def f(x: object, y: object) -> int | None: # Missing return statement
match x, y:
case int(), int() if True:
return 42
case _:
return None
2:
def f(x: object, y: object) -> int | None: # Missing return statement
match x, y:
case _, _ if True:
return 42
case _:
return None
Expected Behavior
- No
Missing return statement
error, because code aftermatch
statement is unreachable. - No
Missing return statement
error and errorstatement is unreachable
on linecase _:
Actual Behavior
- Error
Missing return statement
. - Error
Missing return statement
. Nostatement is unreachable
error on linecase _:
Error Missing return statement
will disappear if i remove if True:
condition (in both cases).
Error statement is unreachable
will appear if i replace case _, _:
with case _:
. Removing condition doesnt help.
Your Environment
- Mypy version used: mypy 0.982 (compiled: no)
- Mypy command-line flags: no
- Mypy configuration options from
mypy.ini
: no - Python version used: 3.11
- Windows 10
And now for something a bit different
def f(x: object, y: object) -> int | None:
match x, y:
case int(), int():
return x + y # Unsupported left operand type for + ("object")
case _:
return None
Mypy cannot narrow types of tuple elements.