Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix case Any() #14479

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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