Skip to content

Commit 6884aa2

Browse files
authored
Fix case Any() in match statement (#14479)
Fixes #14477
1 parent 17e9e22 commit 6884aa2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

mypy/checkpattern.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,12 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
462462
typ: Type = Instance(type_info, [any_type] * len(type_info.defn.type_vars))
463463
elif isinstance(type_info, TypeAlias):
464464
typ = type_info.target
465+
elif (
466+
isinstance(type_info, Var)
467+
and type_info.type is not None
468+
and isinstance(get_proper_type(type_info.type), AnyType)
469+
):
470+
typ = type_info.type
465471
else:
466472
if isinstance(type_info, Var) and type_info.type is not None:
467473
name = type_info.type.str_with_options(self.options)

test-data/unit/check-python310.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,16 @@ match m:
896896
reveal_type(i)
897897
reveal_type(j)
898898

899+
[case testMatchClassPatternAny]
900+
from typing import Any
901+
902+
Foo: Any
903+
m: object
904+
905+
match m:
906+
case Foo():
907+
pass
908+
899909
[case testMatchClassPatternNestedGenerics]
900910
# From cpython test_patma.py
901911
x = [[{0: 0}]]

0 commit comments

Comments
 (0)