Skip to content

Commit

Permalink
Fix case Any() in match statement (#14479)
Browse files Browse the repository at this point in the history
Fixes #14477
  • Loading branch information
ds-cbo authored Sep 2, 2023
1 parent 17e9e22 commit 6884aa2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,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) and type_info.type is not None:
name = type_info.type.str_with_options(self.options)
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -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}]]
Expand Down

0 comments on commit 6884aa2

Please sign in to comment.