Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Vinh-CHUC opened this issue Jul 5, 2024 · 1 comment
Closed

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

Vinh-CHUC opened this issue Jul 5, 2024 · 1 comment
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement

Comments

@Vinh-CHUC
Copy link

Vinh-CHUC commented Jul 5, 2024

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)
@Vinh-CHUC Vinh-CHUC added the bug mypy got something wrong label Jul 5, 2024
@JelleZijlstra JelleZijlstra added the topic-match-statement Python 3.10's match statement label Jul 5, 2024
@hauntsaninja
Copy link
Collaborator

Duplicate of #16835

@hauntsaninja hauntsaninja marked this as a duplicate of #16835 Jul 5, 2024
@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-match-statement Python 3.10's match statement
Projects
None yet
Development

No branches or pull requests

3 participants