Skip to content

Commit 891f7ae

Browse files
committed
Clarification: unpacked arguments
1 parent 4e7c475 commit 891f7ae

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

conformance/results/mypy/overloads_evaluation.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ notes = """
33
Does not expand boolean arguments to Literal[True] and Literal[False].
44
Does not expand enum arguments to literal variants.
55
Does not expand tuple arguments to possible combinations.
6+
Does not handle unpacked arguments when checking for parameter type equivalence.
67
Does not evaluate Any in some cases where overload is ambiguous.
78
Evaluates Any in some cases where overload is not ambiguous.
89
"""
@@ -19,6 +20,7 @@ Line 284: Unexpected errors ['overloads_evaluation.py:284: error: Expression is
1920
Line 306: Unexpected errors ['overloads_evaluation.py:306: error: Expression is of type "Any", not "float" [assert-type]']
2021
Line 350: Unexpected errors ['overloads_evaluation.py:350: error: Expression is of type "list[Any]", not "Any" [assert-type]']
2122
Line 395: Unexpected errors ['overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [assert-type]']
23+
Line 437: Unexpected errors ['overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [assert-type]']
2224
"""
2325
output = """
2426
overloads_evaluation.py:38: error: All overload variants of "example1_1" require at least one argument [call-overload]
@@ -52,4 +54,5 @@ overloads_evaluation.py:284: error: Expression is of type "list[Any]", not "Any"
5254
overloads_evaluation.py:306: error: Expression is of type "Any", not "float" [assert-type]
5355
overloads_evaluation.py:350: error: Expression is of type "list[Any]", not "Any" [assert-type]
5456
overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [assert-type]
57+
overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [assert-type]
5558
"""

conformance/results/results.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,9 @@ <h3>Python Type System Conformance Test Results</h3>
794794
<th class="column col2 conformant">Pass</th>
795795
</tr>
796796
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overloads_evaluation</th>
797-
<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>
797+
<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>
798798
<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>
799-
<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>
799+
<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>
800800
<th class="column col2 conformant">Pass</th>
801801
<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>
802802
</tr>

conformance/results/zuban/overloads_evaluation.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
conformant = "Partial"
22
notes = """
3+
Does not handle unpacked arguments when checking for parameter type equivalence.
34
Returns Any instead of most general return type for ambiguous calls.
45
"""
56
conformance_automated = "Fail"
67
errors_diff = """
78
Line 395: Unexpected errors ['overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [misc]']
9+
Line 437: Unexpected errors ['overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [misc]']
810
Line 464: Unexpected errors ['overloads_evaluation.py:464: error: Expression is of type "Any", not "A[Any]" [misc]']
911
"""
1012
output = """
@@ -23,5 +25,6 @@ overloads_evaluation.py:51: note: def example1_1(x: str) -> str
2325
overloads_evaluation.py:116: error: Argument 1 to "example2" has incompatible type "int | str"; expected "int" [arg-type]
2426
overloads_evaluation.py:116: error: Argument 2 to "example2" has incompatible type "int | str"; expected "str" [arg-type]
2527
overloads_evaluation.py:395: error: Expression is of type "Any", not "int" [misc]
28+
overloads_evaluation.py:437: error: Expression is of type "Any", not "bool" [misc]
2629
overloads_evaluation.py:464: error: Expression is of type "Any", not "A[Any]" [misc]
2730
"""

conformance/tests/overloads_evaluation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,21 +420,21 @@ def check_example10(x: Any):
420420

421421

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

425425

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

429429

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

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

439439

440440
class A[T]:

docs/spec/overload.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,13 @@ Step 5
271271
For each of the candidate overloads, determine whether all arguments satisfy at
272272
least one of the following conditions:
273273

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

279282
If so, eliminate all of the subsequent candidate overloads.
280283

0 commit comments

Comments
 (0)