diff --git a/mypy/checkpattern.py b/mypy/checkpattern.py index e60ed8a11711..cd56b448e447 100644 --- a/mypy/checkpattern.py +++ b/mypy/checkpattern.py @@ -457,6 +457,12 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType: typ: Type = Instance(type_info, [any_type] * len(type_info.defn.type_vars)) elif isinstance(type_info, TypeAlias): typ = type_info.target + elif ( + isinstance(type_info, Var) + and type_info.type is not None + and isinstance(get_proper_type(type_info.type), AnyType) + ): + typ = type_info.type else: if isinstance(type_info, Var): name = str(type_info.type) diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index fb83dda7ffab..036e1404e73b 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -896,6 +896,16 @@ match m: reveal_type(i) reveal_type(j) +[case testMatchClassPatternAny] +from typing import Any + +Foo: Any +m: object + +match m: + case Foo(): + pass + [case testMatchClassPatternNestedGenerics] # From cpython test_patma.py x = [[{0: 0}]]