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 after match statement is unreachable.
- No
Missing return statement error and error statement is unreachable on line case _:
Actual Behavior
- Error
Missing return statement.
- Error
Missing return statement. No statement is unreachable error on line case _:
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.
Bug Report
I have two small similar examples for you:
1:
2:
Expected Behavior
Missing return statementerror, because code aftermatchstatement is unreachable.Missing return statementerror and errorstatement is unreachableon linecase _:Actual Behavior
Missing return statement.Missing return statement. Nostatement is unreachableerror on linecase _:Error
Missing return statementwill disappear if i removeif True:condition (in both cases).Error
statement is unreachablewill appear if i replacecase _, _:withcase _:. Removing condition doesnt help.Your Environment
mypy.ini: noAnd now for something a bit different
Mypy cannot narrow types of tuple elements.