From de4571c7a4dfeb031cf585f6c288b61bb653fe67 Mon Sep 17 00:00:00 2001 From: ds-cbo <82801887+ds-cbo@users.noreply.github.com> Date: Fri, 20 Jan 2023 16:33:16 +0100 Subject: [PATCH] fix case Any() --- mypy/checkpattern.py | 6 ++++++ test-data/unit/check-python310.test | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/mypy/checkpattern.py b/mypy/checkpattern.py index 603b392eee29..57b31109bcd0 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 12fd2b43c80a..bb2e8e46c79b 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}]]