@@ -1620,6 +1620,18 @@ def are_parameters_compatible(
16201620 return True
16211621 trivial_suffix = is_trivial_suffix (right ) and not is_proper_subtype
16221622
1623+ # def _(*a: Unpack[tuple[Any, ...]]) allows any number of arguments, not just infinite.
1624+ if right_star and isinstance (right_star .typ , UnpackType ):
1625+ right_star_inner_type = get_proper_type (right_star .typ .type )
1626+ trivial_varargs = (
1627+ isinstance (right_star_inner_type , Instance )
1628+ and right_star_inner_type .type .fullname == "builtins.tuple"
1629+ and len (right_star_inner_type .args ) == 1
1630+ and isinstance (get_proper_type (right_star_inner_type .args [0 ]), AnyType )
1631+ )
1632+ else :
1633+ trivial_varargs = False
1634+
16231635 if (
16241636 right .arg_kinds == [ARG_STAR ]
16251637 and isinstance (get_proper_type (right .arg_types [0 ]), AnyType )
@@ -1657,14 +1669,16 @@ def are_parameters_compatible(
16571669 # Furthermore, if we're checking for compatibility in all cases,
16581670 # we confirm that if R accepts an infinite number of arguments,
16591671 # L must accept the same.
1660- def _incompatible (left_arg : FormalArgument | None , right_arg : FormalArgument | None ) -> bool :
1672+ def _incompatible (
1673+ left_arg : FormalArgument | None , right_arg : FormalArgument | None , varargs : bool
1674+ ) -> bool :
16611675 if right_arg is None :
16621676 return False
16631677 if left_arg is None :
1664- return not allow_partial_overlap and not trivial_suffix
1678+ return not ( allow_partial_overlap or trivial_suffix or ( varargs and trivial_varargs ))
16651679 return not is_compat (right_arg .typ , left_arg .typ )
16661680
1667- if _incompatible (left_star , right_star ) or _incompatible (left_star2 , right_star2 ):
1681+ if _incompatible (left_star , right_star , True ) or _incompatible (left_star2 , right_star2 , False ):
16681682 return False
16691683
16701684 # Phase 1b: Check non-star args: for every arg right can accept, left must
@@ -1690,7 +1704,7 @@ def _incompatible(left_arg: FormalArgument | None, right_arg: FormalArgument | N
16901704 # arguments. Get all further positional args of left, and make sure
16911705 # they're more general than the corresponding member in right.
16921706 # TODO: are we handling UnpackType correctly here?
1693- if right_star is not None and not trivial_suffix :
1707+ if right_star is not None and not trivial_suffix and not trivial_varargs :
16941708 # Synthesize an anonymous formal argument for the right
16951709 right_by_position = right .try_synthesizing_arg_from_vararg (None )
16961710 assert right_by_position is not None
0 commit comments