Skip to content

Pattern matching: Mypy doesn't narrow tuple[int, int] | int #17490

Closed as not planned
@Vinh-CHUC

Description

@Vinh-CHUC
from typing import assert_never

def foo(arg: tuple[int, int] | int) -> None:
    match arg:
        case (int() as a, int() as b):
            print(f"{a}{b}")
        case int() as c:
            print(f"{c}")
        case _:
            assert_never(arg)

mypy . --strict reports error: Argument 1 to "assert_never" has incompatible type "tuple[int, int]"; expected "NoReturn" [arg-type]

This feels odd? pyright behaves as I'd expect, as the pattern match is exhaustive

Python 3.12.2
mypy 1.10.1 (compiled: yes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions