@@ -553,7 +553,27 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
553553 else :
554554 return False
555555
556- if len (left .args ) == len (right .args ):
556+ if right .type .has_type_var_tuple_type :
557+ # Similar to subtyping, we delegate the heavy lifting to the tuple overlap.
558+ assert right .type .type_var_tuple_prefix is not None
559+ assert right .type .type_var_tuple_suffix is not None
560+ prefix = right .type .type_var_tuple_prefix
561+ suffix = right .type .type_var_tuple_suffix
562+ tvt = right .type .defn .type_vars [prefix ]
563+ assert isinstance (tvt , TypeVarTupleType )
564+ fallback = tvt .tuple_fallback
565+ left_prefix , left_middle , left_suffix = split_with_prefix_and_suffix (
566+ left .args , prefix , suffix
567+ )
568+ right_prefix , right_middle , right_suffix = split_with_prefix_and_suffix (
569+ right .args , prefix , suffix
570+ )
571+ left_args = left_prefix + (TupleType (list (left_middle ), fallback ),) + left_suffix
572+ right_args = right_prefix + (TupleType (list (right_middle ), fallback ),) + right_suffix
573+ else :
574+ left_args = left .args
575+ right_args = right .args
576+ if len (left_args ) == len (right_args ):
557577 # Note: we don't really care about variance here, since the overlapping check
558578 # is symmetric and since we want to return 'True' even for partial overlaps.
559579 #
@@ -570,7 +590,7 @@ def _type_object_overlap(left: Type, right: Type) -> bool:
570590 # to contain only instances of B at runtime.
571591 if all (
572592 _is_overlapping_types (left_arg , right_arg )
573- for left_arg , right_arg in zip (left . args , right . args )
593+ for left_arg , right_arg in zip (left_args , right_args )
574594 ):
575595 return True
576596
0 commit comments