|
54 | 54 | get_proper_type, |
55 | 55 | split_with_prefix_and_suffix, |
56 | 56 | ) |
57 | | -from mypy.typevars import fill_typevars |
| 57 | +from mypy.typevars import fill_typevars, fill_typevars_with_any |
58 | 58 | from mypy.visitor import PatternVisitor |
59 | 59 |
|
60 | 60 | self_match_type_names: Final = [ |
@@ -544,16 +544,7 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType: |
544 | 544 | self.msg.fail(message_registry.CLASS_PATTERN_GENERIC_TYPE_ALIAS, o) |
545 | 545 | return self.early_non_match() |
546 | 546 | if isinstance(type_info, TypeInfo): |
547 | | - any_type = AnyType(TypeOfAny.implementation_artifact) |
548 | | - args: list[Type] = [] |
549 | | - for tv in type_info.defn.type_vars: |
550 | | - if isinstance(tv, TypeVarTupleType): |
551 | | - args.append( |
552 | | - UnpackType(self.chk.named_generic_type("builtins.tuple", [any_type])) |
553 | | - ) |
554 | | - else: |
555 | | - args.append(any_type) |
556 | | - typ: Type = Instance(type_info, args) |
| 547 | + typ: Type = fill_typevars_with_any(type_info) |
557 | 548 | elif isinstance(type_info, TypeAlias): |
558 | 549 | typ = type_info.target |
559 | 550 | elif ( |
@@ -703,6 +694,8 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType: |
703 | 694 |
|
704 | 695 | def should_self_match(self, typ: Type) -> bool: |
705 | 696 | typ = get_proper_type(typ) |
| 697 | + if isinstance(typ, TupleType): |
| 698 | + typ = typ.partial_fallback |
706 | 699 | if isinstance(typ, Instance) and typ.type.get("__match_args__") is not None: |
707 | 700 | # Named tuples and other subtypes of builtins that define __match_args__ |
708 | 701 | # should not self match. |
|
0 commit comments