Skip to content

Unreachable false positive in match statement with tuples #19981

@brandonchinn178

Description

@brandonchinn178

Bug Report

input: tuple[list, list]
match input:
    case _, []:
        print(1)
    case [], _:
        print(2)
    case _:
        print(3)

This is perfectly valid at runtime, but mypy warns about unreachable at print(2). reveal_type shows tuple[Never, list].

To Reproduce

https://mypy-play.net/?mypy=master&python=3.12&flags=strict%2Cwarn-unreachable&gist=772131f18fb17abb981f7485732713e7

Expected Behavior

Should not error

Actual Behavior

main.py:6: error: Statement is unreachable  [unreachable]
main.py:8: note: Revealed type is "tuple[Never, builtins.list[builtins.int]]"
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used:
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions