8000 Add additional Unpack/kwargs conformance test cases (#1918) · python/typing@53daf3c · GitHub
[go: up one dir, main page]

Skip to content

Commit 53daf3c

Browse files
Add additional Unpack/kwargs conformance test cases (#1918)
* add content from typeshed/CONTRIBUTING.md * fix build errors * address review comments * Update docs/guides/writing_stubs.rst Co-authored-by: Rebecca Chen <rchen152@gmail.com> * Update docs/guides/writing_stubs.rst Co-authored-by: Rebecca Chen <rchen152@gmail.com> * add Incomplete vs Any, the Any trick sections; add reference to error suppression formats section * fix ref * format and fix link * fix backticks, add Docstrings section * fix one more backtick * fix typo * fix label * Minor style and formatting fixes Removed repeated example, fixed formatting, removed stray "the". * Add additional callable kwargs conformance tests * add comments and notes * remove 2nd example --------- Co-authored-by: Rebecca Chen <rchen152@gmail.com>
1 parent b97d71b commit 53daf3c

File tree

9 files changed

+33
-12
lines changed

9 files changed

+33
-12
lines changed

conformance/results/mypy/callables_kwargs.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Allows callable without kwargs to be assigned to callable with unpacked kwargs
4+
"""
25
output = """
36
callables_kwargs.py:22: note: "func1" defined here
47
callables_kwargs.py:46: error: Missing named argument "v1" for "func1" [call-arg]
@@ -21,6 +24,7 @@ callables_kwargs.py:103: note: "TDProtocol5.__call__" has type "Callable[[Arg(in
2124
callables_kwargs.py:111: error: Overlap between argument names and ** TypedDict items: "v1" [misc]
2225
callables_kwargs.py:122: error: Unpack item in ** argument must be a TypedDict [misc]
2326
"""
24-
conformance_automated = "Pass"
27+
conformance_automated = "Fail"
2528
errors_diff = """
29+
Line 134: Expected 1 errors
2630
"""

conformance/results/mypy/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.15.0"
2-
test_duration = 2.0
2+
test_duration = 1.2

conformance/results/pyre/callables_kwargs.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ callables_kwargs.py:102:0 Incompatible variable type [9]: v4 is declared to have
1515
callables_kwargs.py:103:0 Incompatible variable type [9]: v5 is declared to have type `TDProtocol5` but is used as type `typing.Callable(func1)[[Keywords(Unpack[TD2])], None]`.
1616
callables_kwargs.py:111:21 Duplicate parameter [65]: Duplicate parameter name `v1`.
1717
callables_kwargs.py:122:12 Invalid type [31]: `Unpack` in kwargs may only be used with typed dictionaries. `Variable[T (bound to TD2)]` is not a typed dictionary.
18+
callables_kwargs.py:134:0 Incompatible variable type [9]: v7 is declared to have type `TDProtocol6` but is used as type `typing.Callable(func7)[[KeywordOnly(v1, int), KeywordOnly(v3, str), KeywordOnly(v2, str, default)], None]`.
1819
"""
1920
conformance_automated = "Pass"
2021
errors_diff = """

conformance/results/pyre/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.23"
2-
test_duration = 6.5
2+
test_duration = 7.8

conformance/results/pyright/callables_kwargs.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Allows callable without kwargs to be assigned to callable with unpacked kwargs
4+
"""
25
output = """
36
callables_kwargs.py:28:5 - error: Could not access item in TypedDict
47
  "v2" is not a required key in "TD2", so access may result in runtime exception (reportTypedDictNotRequiredAccess)
@@ -28,6 +31,7 @@ callables_kwargs.py:103:19 - error: Type "(**kwargs: **TD2) -> None" is not assi
2831
callables_kwargs.py:111:30 - error: Typed dictionary overlaps with keyword parameter: v1 (reportGeneralTypeIssues)
2932
callables_kwargs.py:122:21 - error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues)
3033
"""
31-
conformance_automated = "Pass"
34+
conformance_automated = "Fail"
3235
errors_diff = """
36+
Line 134: Expected 1 errors
3337
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyright 1.1.393"
2-
test_duration = 1.2
2+
test_duration = 1.4

conformance/results/pytype/callables_kwargs.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Line 102: Expected 1 errors
8282
Line 103: Expected 1 errors
8383
Line 111: Expected 1 errors
8484
Line 122: Expected 1 errors
85+
Line 134: Expected 1 errors
8586
Line 10: Unexpected errors ['callables_kwargs.py:10:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: typing.Unpack not supported yet [not-supported-yet]']
8687
Line 24: Unexpected errors ['callables_kwargs.py:24:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func1: Unpack[TD2] [assert-type]']
8788
Line 32: Unexpected errors ['callables_kwargs.py:32:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func1: Unpack[TD2] [assert-type]']

conformance/results/results.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ <h3>Python Type System Conformance Test Results</h3>
159159
<div class="table_container"><table><tbody>
160160
<tr><th class="col1">&nbsp;</th>
161161
<th class='tc-header'><div class='tc-name'>mypy 1.15.0</div>
162-
<div class='tc-time'>2.0sec</div>
162+
<div class='tc-time'>1.2sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.393</div>
165-
<div class='tc-time'>1.2sec</div>
165+
<div class='tc-time'>1.4sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>6.5sec</div>
168+
<div class='tc-time'>7.8sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171171
<div class='tc-time'>36.6sec</div>
@@ -607,8 +607,8 @@ <h3>Python Type System Conformance Test Results</h3>
607607
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not support Concatenate.</p><p>Does not treat "*args: Any, **kwargs: Any" as "...".</p></span></div></th>
608608
</tr>
609609
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;callables_kwargs</th>
610-
<th class="column col2 conformant">Pass</th>
611-
<th class="column col2 conformant">Pass</th>
610+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Allows callable without kwargs to be assigned to callable with unpacked kwargs</p></span></div></th>
611+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Allows callable without kwargs to be assigned to callable with unpacked kwargs</p></span></div></th>
612612
<th class="column col2 conformant">Pass</th>
613613
<th class="column col2 not-conformant"><div class="hover-text">Unsupported<span class="tooltip-text" id="bottom"><p>Does not understand Unpack in the context of **kwargs annotation.</p></span></div></th>
614614
</tr>

conformance/tests/callables_kwargs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,14 @@ def func5(v1: int, **kwargs: Unpack[TD2]) -> None: # E: parameter v1 overlaps w
121121

122122
def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a TypedDict, not a TypeVar bound to TypedDict.
123123
...
124+
125+
# > The situation where the destination callable contains **kwargs: Unpack[TypedDict] and
126+
# > the source callable doesn’t contain **kwargs should be disallowed. This is because,
127+
# > we cannot be sure that additional keyword arguments are not being passed in when an instance of a subclass
128+
# > had been assigned to a variable with a base class type and then unpacked in the destination callable invocation
129+
130+
def func7(*, v1: int, v3: str, v2: str = "") -> None:
131+
...
132+
133+
134+
v7: TDProtocol6 = func7 # E: source does not have kwargs

0 commit comments

Comments
 (0)
0