@@ -2449,7 +2449,7 @@ def erase_override(t: Type) -> Type:
24492449 if not is_subtype (original_arg_type , erase_override (override_arg_type )):
24502450 context : Context = node
24512451 if isinstance (node , FuncDef ) and not node .is_property :
2452- arg_node = node .arguments [i + len ( override .bound_args )]
2452+ arg_node = node .arguments [i + override .bound ( )]
24532453 if arg_node .line != - 1 :
24542454 context = arg_node
24552455 self .msg .argument_incompatible_with_supertype (
@@ -2664,7 +2664,7 @@ def check_typevar_defaults(self, tvars: Sequence[TypeVarLikeType]) -> None:
26642664 continue
26652665 if not is_subtype (tv .default , tv .upper_bound ):
26662666 self .fail ("TypeVar default must be a subtype of the bound type" , tv )
2667- if tv .values and not any (tv .default == value for value in tv .values ):
2667+ if tv .values and not any (is_same_type ( tv .default , value ) for value in tv .values ):
26682668 self .fail ("TypeVar default must be one of the constraint types" , tv )
26692669
26702670 def check_enum (self , defn : ClassDef ) -> None :
@@ -5455,6 +5455,7 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
54555455 inferred_types = self .infer_variable_types_from_type_maps (type_maps )
54565456
54575457 # The second pass narrows down the types and type checks bodies.
5458+ unmatched_types : TypeMap = None
54585459 for p , g , b in zip (s .patterns , s .guards , s .bodies ):
54595460 current_subject_type = self .expr_checker .narrow_type_from_binder (
54605461 named_subject , subject_type
@@ -5511,6 +5512,11 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
55115512 else :
55125513 self .accept (b )
55135514 self .push_type_map (else_map , from_assignment = False )
5515+ unmatched_types = else_map
5516+
5517+ if unmatched_types is not None :
5518+ for typ in list (unmatched_types .values ()):
5519+ self .msg .match_statement_inexhaustive_match (typ , s )
55145520
55155521 # This is needed due to a quirk in frame_context. Without it types will stay narrowed
55165522 # after the match.
@@ -7691,9 +7697,13 @@ def get_isinstance_type(self, expr: Expression) -> list[TypeRange] | None:
76917697 types : list [TypeRange ] = []
76927698 for typ in all_types :
76937699 if isinstance (typ , FunctionLike ) and typ .is_type_obj ():
7694- # Type variables may be present -- erase them, which is the best
7695- # we can do (outside disallowing them here).
7696- erased_type = erase_typevars (typ .items [0 ].ret_type )
7700+ # If a type is generic, `isinstance` can only narrow its variables to Any.
7701+ any_parameterized = fill_typevars_with_any (typ .type_object ())
7702+ # Tuples may have unattended type variables among their items
7703+ if isinstance (any_parameterized , TupleType ):
7704+ erased_type = erase_typevars (any_parameterized )
7705+ else :
7706+ erased_type = any_parameterized
76977707 types .append (TypeRange (erased_type , is_upper_bound = False ))
76987708 elif isinstance (typ , TypeType ):
76997709 # Type[A] means "any type that is a subtype of A" rather than "precisely type A"
0 commit comments