Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional Unpack/kwargs conformance test cases #1918

Merged
merged 20 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions conformance/results/mypy/callables_kwargs.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
conformant = "Pass"
conformant = "Partial"
notes = """
Allows callable without kwargs to be assigned to callable with unpacked kwargs
"""
output = """
callables_kwargs.py:22: note: "func1" defined here
callables_kwargs.py:46: error: Missing named argument "v1" for "func1" [call-arg]
Expand All @@ -21,6 +24,7 @@ callables_kwargs.py:103: note: "TDProtocol5.__call__" has type "Callable[[Arg(in
callables_kwargs.py:111: error: Overlap between argument names and ** TypedDict items: "v1" [misc]
callables_kwargs.py:122: error: Unpack item in ** argument must be a TypedDict [misc]
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Line 134: Expected 1 errors
"""
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.15.0"
test_duration = 2.0
test_duration = 1.2
1 change: 1 addition & 0 deletions conformance/results/pyre/callables_kwargs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ callables_kwargs.py:102:0 Incompatible variable type [9]: v4 is declared to have
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]`.
callables_kwargs.py:111:21 Duplicate parameter [65]: Duplicate parameter name `v1`.
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.
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]`.
"""
conformance_automated = "Pass"
errors_diff = """
Expand Down
2 changes: 1 addition & 1 deletion conformance/results/pyre/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyre 0.9.23"
test_duration = 6.5
test_duration = 7.8
8 changes: 6 additions & 2 deletions conformance/results/pyright/callables_kwargs.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
conformant = "Pass"
conformant = "Partial"
notes = """
Allows callable without kwargs to be assigned to callable with unpacked kwargs
"""
output = """
callables_kwargs.py:28:5 - error: Could not access item in TypedDict
  "v2" is not a required key in "TD2", so access may result in runtime exception (reportTypedDictNotRequiredAccess)
Expand Down Expand Up @@ -28,6 +31,7 @@ callables_kwargs.py:103:19 - error: Type "(**kwargs: **TD2) -> None" is not assi
callables_kwargs.py:111:30 - error: Typed dictionary overlaps with keyword parameter: v1 (reportGeneralTypeIssues)
callables_kwargs.py:122:21 - error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Line 134: Expected 1 errors
"""
2 changes: 1 addition & 1 deletion conformance/results/pyright/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyright 1.1.393"
test_duration = 1.2
test_duration = 1.4
1 change: 1 addition & 0 deletions conformance/results/pytype/callables_kwargs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Line 102: Expected 1 errors
Line 103: Expected 1 errors
Line 111: Expected 1 errors
Line 122: Expected 1 errors
Line 134: Expected 1 errors
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]']
Line 24: Unexpected errors ['callables_kwargs.py:24:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func1: Unpack[TD2] [assert-type]']
Line 32: Unexpected errors ['callables_kwargs.py:32:9: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func1: Unpack[TD2] [assert-type]']
Expand Down
10 changes: 5 additions & 5 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ <h3>Python Type System Conformance Test Results</h3>
<div class="table_container"><table><tbody>
<tr><th class="col1">&nbsp;</th>
<th class='tc-header'><div class='tc-name'>mypy 1.15.0</div>
<div class='tc-time'>2.0sec</div>
<div class='tc-time'>1.2sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyright 1.1.393</div>
<div class='tc-time'>1.2sec</div>
<div class='tc-time'>1.4sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
<div class='tc-time'>6.5sec</div>
<div class='tc-time'>7.8sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
<div class='tc-time'>36.6sec</div>
Expand Down Expand Up @@ -607,8 +607,8 @@ <h3>Python Type System Conformance Test Results</h3>
<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>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;callables_kwargs</th>
<th class="column col2 conformant">Pass</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>Allows callable without kwargs to be assigned to callable with unpacked kwargs</p></span></div></th>
<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>
<th class="column col2 conformant">Pass</th>
<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>
</tr>
Expand Down
11 changes: 11 additions & 0 deletions conformance/tests/callables_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ def func5(v1: int, **kwargs: Unpack[TD2]) -> None: # E: parameter v1 overlaps w

def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a TypedDict, not a TypeVar bound to TypedDict.
...

# > The situation where the destination callable contains **kwargs: Unpack[TypedDict] and
# > the source callable doesn’t contain **kwargs should be disallowed. This is because,
# > we cannot be sure that additional keyword arguments are not being passed in when an instance of a subclass
# > had been assigned to a variable with a base class type and then unpacked in the destination callable invocation

def func7(*, v1: int, v3: str, v2: str = "") -> None:
...


v7: TDProtocol6 = func7 # E: source does not have kwargs