Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Remove unnecessary error message for match class patterns
  • Loading branch information
cdce8p committed Aug 21, 2025
commit a9aa418b6508fb2ccf7eddcbffa46a90cda240a7
8 changes: 4 additions & 4 deletions mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
#
type_info = o.class_ref.node
if type_info is None:
return PatternType(AnyType(TypeOfAny.from_error), AnyType(TypeOfAny.from_error), {})
if isinstance(type_info, TypeAlias) and not type_info.no_args:
typ: Type = AnyType(TypeOfAny.from_error)
elif isinstance(type_info, TypeAlias) and not type_info.no_args:
self.msg.fail(message_registry.CLASS_PATTERN_GENERIC_TYPE_ALIAS, o)
return self.early_non_match()
if isinstance(type_info, TypeInfo):
typ: Type = fill_typevars_with_any(type_info)
elif isinstance(type_info, TypeInfo):
typ = fill_typevars_with_any(type_info)
elif isinstance(type_info, TypeAlias):
typ = type_info.target
elif (
Expand Down
9 changes: 5 additions & 4 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,14 @@ m: object
match m:
case xyz(y): # E: Name "xyz" is not defined
reveal_type(m) # N: Revealed type is "Any"
reveal_type(y) # E: Cannot determine type of "y" \
# N: Revealed type is "Any"
reveal_type(y) # N: Revealed type is "Any"

match m:
case xyz(z=x): # E: Name "xyz" is not defined
reveal_type(x) # E: Cannot determine type of "x" \
# N: Revealed type is "Any"
reveal_type(x) # N: Revealed type is "Any"
case (xyz1() as n) | (xyz2(attr=n)): # E: Name "xyz1" is not defined \
# E: Name "xyz2" is not defined
reveal_type(n) # N: Revealed type is "Any"

[case testMatchClassPatternCaptureDataclass]
from dataclasses import dataclass
Expand Down
Loading