Skip to content
Prev Previous commit
Next Next commit
Clarification: unpacked arguments
  • Loading branch information
rchen152 committed Apr 8, 2026
commit 891f7ae7f39c13698f96dfcd994076adf3a7dcb3
3 changes: 3 additions & 0 deletions conformance/results/mypy/overloads_evaluation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ notes = """
Does not expand boolean arguments to Literal[True] and Literal[False].
Does not expand enum arguments to literal variants.
Does not expand tuple arguments to possible combinations.
Does not handle unpacked arguments when checking for parameter type equivalence.
Does not evaluate Any in some cases where overload is ambiguous.
Evaluates Any in some cases where overload is not ambiguous.
"""
Expand All @@ -19,6 +20,7 @@ Line 284: Unexpected errors ['overloads_evaluation.py:284: error: Expression is
Line 306: Unexpected errors ['overloads_evaluation.py:306: error: Expression is of type "Any", not "float" [assert-type]']
Line 350: Unexpected errors ['overloads_evaluation.py:350: error: Expression is of type "list[Any]", not "Any" [assert-type]']
Line 395: Unexpected errors ['overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [assert-type]']
Line 437: Unexpected errors ['overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [assert-type]']
"""
output = """
overloads_evaluation.py:38: error: All overload variants of "example1_1" require at least one argument [call-overload]
Expand Down Expand Up @@ -52,4 +54,5 @@ overloads_evaluation.py:284: error: Expression is of type "list[Any]", not "Any"
overloads_evaluation.py:306: error: Expression is of type "Any", not "float" [assert-type]
overloads_evaluation.py:350: error: Expression is of type "list[Any]", not "Any" [assert-type]
overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [assert-type]
overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [assert-type]
"""
4 changes: 2 additions & 2 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,9 @@ <h3>Python Type System Conformance Test Results</h3>
<th class="column col2 conformant">Pass</th>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_evaluation</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not expand boolean arguments to Literal[True] and Literal[False].</p><p>Does not expand enum arguments to literal variants.</p><p>Does not expand tuple arguments to possible combinations.</p><p>Does not evaluate Any in some cases where overload is ambiguous.</p><p>Evaluates Any in some cases where overload is not ambiguous.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not expand boolean arguments to Literal[True] and Literal[False].</p><p>Does not expand enum arguments to literal variants.</p><p>Does not expand tuple arguments to possible combinations.</p><p>Does not handle unpacked arguments when checking for parameter type equivalence.</p><p>Does not evaluate Any in some cases where overload is ambiguous.</p><p>Evaluates Any in some cases where overload is not ambiguous.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not evaluate Any in some cases where overload is ambiguous.</p><p>Picks first overload instead of most general return type in some cases where overload is ambiguous.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Returns Any instead of most general return type for ambiguous calls.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not handle unpacked arguments when checking for parameter type equivalence.</p><p>Returns Any instead of most general return type for ambiguous calls.</p></span></div></th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Returns Any instead of most general return type for ambiguous calls.</p></span></div></th>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions conformance/results/zuban/overloads_evaluation.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
conformant = "Partial"
notes = """
Does not handle unpacked arguments when checking for parameter type equivalence.
Returns Any instead of most general return type for ambiguous calls.
"""
conformance_automated = "Fail"
errors_diff = """
Line 395: Unexpected errors ['overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [misc]']
Line 437: Unexpected errors ['overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [misc]']
Line 464: Unexpected errors ['overloads_evaluation.py:464: error: Expression is of type "Any", not "A[Any]" [misc]']
"""
output = """
Expand All @@ -23,5 +25,6 @@ overloads_evaluation.py:51: note: def example1_1(x: str) -> str
overloads_evaluation.py:116: error: Argument 1 to "example2" has incompatible type "int | str"; expected "int" [arg-type]
overloads_evaluation.py:116: error: Argument 2 to "example2" has incompatible type "int | str"; expected "str" [arg-type]
overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [misc]
overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [misc]
overloads_evaluation.py:464: error: Expression is of type "Any", not "A[Any]" [misc]
"""
16 changes: 8 additions & 8 deletions conformance/tests/overloads_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,21 +420,21 @@ def check_example10(x: Any):


@overload
def example11(x: int) -> bool: ...
def example11(x: Literal['o1'], y: int, z: str) -> bool: ...


@overload
def example11(**kwargs: int) -> int: ...
def example11(x: str, y: int, z: str) -> int: ...


def example11(*args: int, **kwargs: int) -> int:
return 0
def example11(x: str, y: int, z: str) -> bool | int:
return True


def check_example11(x: Any):
# The parameters corresponding to argument `x` (`x` in the first overload
# and `**kwargs` in the second) both have type `int`, so the second
# overload can be eliminated.
assert_type(example11(x=x), bool)
# `*x` maps to `(y: int, z: str)` in both overloads, so the second overload
# can be eliminated.
assert_type(example11('o1', *x), bool)


class A[T]:
Expand Down
11 changes: 7 additions & 4 deletions docs/spec/overload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,13 @@ Step 5
For each of the candidate overloads, determine whether all arguments satisfy at
least one of the following conditions:

- All possible :term:`materializations <materialize>` of the argument's type are
assignable to the corresponding parameter type, or
- The parameter types corresponding to this argument in all of the candidate overloads
are :term:`equivalent`.
- All possible :term:`materializations <materialize>` of the argument's type
are assignable to the corresponding parameter type, or
- The parameter types corresponding to this argument in all of the candidate
overloads are :term:`equivalent`. For an unpacked argument, this condition is
satisfied if the argument maps to the same number of parameters in all
candidate overloads, and for each parameter, the types in all candidate
overloads are equivalent.

If so, eliminate all of the subsequent candidate overloads.

Expand Down