-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as not planned
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-reachabilityDetecting unreachable codeDetecting unreachable codetopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
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 None2:
def f(x: object, y: object) -> int | None: # Missing return statement
match x, y:
case _, _ if True:
return 42
case _:
return NoneExpected Behavior
- No
Missing return statementerror, because code aftermatchstatement is unreachable. - No
Missing return statementerror and errorstatement is unreachableon linecase _:
Actual Behavior
- Error
Missing return statement. - Error
Missing return statement. Nostatement is unreachableerror 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 NoneMypy cannot narrow types of tuple elements.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-reachabilityDetecting unreachable codeDetecting unreachable codetopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder