@@ -2449,7 +2449,7 @@ def erase_override(t: Type) -> Type:
2449
2449
if not is_subtype (original_arg_type , erase_override (override_arg_type )):
2450
2450
context : Context = node
2451
2451
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 ( )]
2453
2453
if arg_node .line != - 1 :
2454
2454
context = arg_node
2455
2455
self .msg .argument_incompatible_with_supertype (
@@ -2664,7 +2664,7 @@ def check_typevar_defaults(self, tvars: Sequence[TypeVarLikeType]) -> None:
2664
2664
continue
2665
2665
if not is_subtype (tv .default , tv .upper_bound ):
2666
2666
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 ):
2668
2668
self .fail ("TypeVar default must be one of the constraint types" , tv )
2669
2669
2670
2670
def check_enum (self , defn : ClassDef ) -> None :
@@ -5455,6 +5455,7 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
5455
5455
inferred_types = self .infer_variable_types_from_type_maps (type_maps )
5456
5456
5457
5457
# The second pass narrows down the types and type checks bodies.
5458
+ unmatched_types : TypeMap = None
5458
5459
for p , g , b in zip (s .patterns , s .guards , s .bodies ):
5459
5460
current_subject_type = self .expr_checker .narrow_type_from_binder (
5460
5461
named_subject , subject_type
@@ -5511,6 +5512,11 @@ def visit_match_stmt(self, s: MatchStmt) -> None:
5511
5512
else :
5512
5513
self .accept (b )
5513
5514
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 )
5514
5520
5515
5521
# This is needed due to a quirk in frame_context. Without it types will stay narrowed
5516
5522
# after the match.
@@ -7691,9 +7697,13 @@ def get_isinstance_type(self, expr: Expression) -> list[TypeRange] | None:
7691
7697
types : list [TypeRange ] = []
7692
7698
for typ in all_types :
7693
7699
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
7697
7707
types .append (TypeRange (erased_type , is_upper_bound = False ))
7698
7708
elif isinstance (typ , TypeType ):
7699
7709
# Type[A] means "any type that is a subtype of A" rather than "precisely type A"
0 commit comments