diff --git a/mypy/subtypes.py b/mypy/subtypes.py index 143d6783f43e..9219bf1c544b 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -2117,7 +2117,8 @@ def covers_at_runtime(item: Type, supertype: Type) -> bool: supertype = get_proper_type(supertype) # Since runtime type checks will ignore type arguments, erase the types. - supertype = erase_type(supertype) + if not (isinstance(supertype, CallableType) and supertype.is_type_obj()): + supertype = erase_type(supertype) if is_proper_subtype( erase_type(item), supertype, ignore_promotions=True, erase_instances=True ): diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index 0695bd0380cb..bb8f038eb1eb 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -2601,6 +2601,28 @@ def f(t: T) -> None: reveal_type(k) # N: Revealed type is "tuple[builtins.int, fallback=__main__.K]" [builtins fixtures/tuple.pyi] +[case testMatchTypeObjectTypeVar] +# flags: --warn-unreachable +from typing import TypeVar +import b + +T_Choice = TypeVar("T_Choice", bound=b.One | b.Two) + +def switch(choice: type[T_Choice]) -> None: + match choice: + case b.One: + reveal_type(choice) # N: Revealed type is "def () -> b.One" + case b.Two: + reveal_type(choice) # N: Revealed type is "def () -> b.Two" + case _: + reveal_type(choice) # N: Revealed type is "type[T_Choice`-1]" + +[file b.py] +class One: ... +class Two: ... + +[builtins fixtures/tuple.pyi] + [case testNewRedefineMatchBasics] # flags: --allow-redefinition-new --local-partial-types