Skip to content
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

Structural Pattern Matching Exhaustiveness check when using OR #18108

Closed
acciaioli opened this issue Nov 5, 2024 · 0 comments · Fixed by #18119
Closed

Structural Pattern Matching Exhaustiveness check when using OR #18108

acciaioli opened this issue Nov 5, 2024 · 0 comments · Fixed by #18119
Labels
bug mypy got something wrong good-second-issue topic-match-statement Python 3.10's match statement

Comments

@acciaioli
Copy link

acciaioli commented Nov 5, 2024

Bug Report

Mypy fails to identify missing value comparisons in my match when I use |

To Reproduce

Gist URL
Playground URL

from typing import Literal, assert_never

Color = Literal["blue", "green", "red"]


def print_color(color: Color) -> None:
  match color:
      case "blue":
          print("blue")
      case "green" | "kangaroo":
          print("green")
      case _:
          assert_never(color)

Expected Behavior

I expected mypy to error because I missed checking against red

colors.py:13: error: Argument 1 to "assert_never" has incompatible type "Literal['red']"; expected "Never"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Actual Behavior

Mypy doesn't raise any errors

Success: no issues found in 1 source file

** Extra Context **

This only happens when I use |.
I don't use pyright but ran it to see if I was the one missing something but I believe they do flag it correctly

colors.py:13:24 - error: Argument of type "Literal['red']" cannot be assigned to parameter "arg" of type "Never" in function "assert_never"
    Type "Literal['red']" is not assignable to type "Never" (reportArgumentType)

Your Environment

  • Mypy version used: mypy 1.13.0 (compiled: yes)
  • Mypy command-line flags: --strict
  • Python version used: Python 3.11.6
@acciaioli acciaioli added the bug mypy got something wrong label Nov 5, 2024
@JelleZijlstra JelleZijlstra added the topic-match-statement Python 3.10's match statement label Nov 5, 2024
@JukkaL JukkaL closed this as completed in f067db4 Nov 11, 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 good-second-issue topic-match-statement Python 3.10's match statement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants