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

Cannot infer type of generic type parm in match case statement #18470

Open
pbabics opened this issue Jan 15, 2025 · 0 comments
Open

Cannot infer type of generic type parm in match case statement #18470

pbabics opened this issue Jan 15, 2025 · 0 comments
Labels
bug mypy got something wrong

Comments

@pbabics
Copy link

pbabics commented Jan 15, 2025

Bug Report
Hello,

I've been trying to create a Generic function with a match statement, as seen below, but I am getting errors about expected_result_type not being a type, although from the typing, it most certainly is.

This might be related to #18432

To Reproduce

from collections.abc import Callable
from typing import Any


def print_test[T](fn: Callable[[], Any], expected_result_type: type[T]) -> T:
    value = fn()

    match value:
        case expected_result_type():
            return value
        case str():
            print("Got ", value)
        case _:
            print("Unexpected result ", value)


print_test(lambda: 4, float)

Expected Behavior

No errors

Actual Behavior

test.py:9: error: Expected type in class pattern; found "type[T`-1]"  [misc]
test.py:10: error: Statement is unreachable  [unreachable]

Your Environment

  • Mypy version used: 1.14.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.13.0
@pbabics pbabics added the bug mypy got something wrong label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant