Skip to content

Commit 2678723

Browse files
committed
link to terms & handle implicitly open typeddicts the same as explicitly open ones
1 parent 8368356 commit 2678723

9 files changed

Lines changed: 27 additions & 60 deletions

File tree

‎conformance/results/mypy/callables_kwargs.toml‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ callables_kwargs.py:104: note: "TDProtocol5.__call__" has type "def __call__(sel
2727
callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc]
2828
callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc]
2929
callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]
30-
callables_kwargs.py:149: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]
31-
callables_kwargs.py:153: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]
32-
callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]
30+
callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]
3331
"""
3432
conformance_automated = "Fail"
3533
errors_diff = """
3634
Line 135: Expected 1 errors
37-
Line 176: Expected 1 errors
38-
Line 194: Expected 1 errors
39-
Line 195: Expected 1 errors
35+
Line 184: Expected 1 errors
36+
Line 185: Expected 1 errors
4037
Line 145: Unexpected errors ['callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]']
41-
Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]']
42-
Line 153: Unexpected errors ['callables_kwargs.py:153: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]']
43-
Line 193: Unexpected errors ['callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]']
38+
Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]']
4439
"""

‎conformance/results/pycroscope/callables_kwargs.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ Does not check the `extra_items` type of unpacked kwargs against the target call
66
"""
77
conformance_automated = "Fail"
88
errors_diff = """
9-
Line 176: Expected 1 errors
10-
Line 194: Expected 1 errors
11-
Line 195: Expected 1 errors
9+
Line 184: Expected 1 errors
10+
Line 185: Expected 1 errors
1211
"""
1312
output = """
1413
./callables_kwargs.py:47:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call]

‎conformance/results/pyrefly/callables_kwargs.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ Does not check the `extra_items` type of unpacked kwargs against the target call
66
"""
77
conformance_automated = "Fail"
88
errors_diff = """
9-
Line 176: Expected 1 errors
10-
Line 194: Expected 1 errors
11-
Line 195: Expected 1 errors
9+
Line 184: Expected 1 errors
10+
Line 185: Expected 1 errors
1211
"""
1312
output = """
1413
ERROR callables_kwargs.py:47:10-12: Missing argument `v1` in function `func1` [missing-argument]

‎conformance/results/pyright/callables_kwargs.toml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ callables_kwargs.py:123:21 - error: Expected TypedDict type argument for Unpack
3434
callables_kwargs.py:135:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"
3535
  Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"
3636
    Parameter "**kwargs" has no corresponding parameter (reportAssignmentType)
37-
callables_kwargs.py:180:5 - error: Function declaration "func10" is obscured by a declaration of the same name (reportRedeclaration)
38-
callables_kwargs.py:195:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"
37+
callables_kwargs.py:185:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"
3938
  "int" is not assignable to "str" (reportArgumentType)
4039
"""
4140
conformance_automated = "Fail"
4241
errors_diff = """
43-
Line 176: Expected 1 errors
44-
Line 194: Expected 1 errors
45-
Line 180: Unexpected errors ['callables_kwargs.py:180:5 - error: Function declaration "func10" is obscured by a declaration of the same name (reportRedeclaration)']
42+
Line 184: Expected 1 errors
4643
"""

‎conformance/results/results.html‎

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎conformance/results/ty/callables_kwargs.toml‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
conformant = "Partial"
2-
notes = """
3-
Does not reject passing unpacked kwargs typed with an open TypedDict to a callable that has no `**kwargs`.
4-
"""
5-
conformance_automated = "Fail"
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
63
errors_diff = """
7-
Line 176: Expected 1 errors
84
"""
95
output = """
106
callables_kwargs.py:47:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1`
@@ -22,6 +18,6 @@ callables_kwargs.py:104:19: error[invalid-assignment] Object of type `def func1(
2218
callables_kwargs.py:112:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation
2319
callables_kwargs.py:123:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6`
2420
callables_kwargs.py:135:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6`
25-
callables_kwargs.py:194:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name`
26-
callables_kwargs.py:195:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int`
21+
callables_kwargs.py:184:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name`
22+
callables_kwargs.py:185:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int`
2723
"""

‎conformance/results/zuban/callables_kwargs.toml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_i
55
"""
66
conformance_automated = "Fail"
77
errors_diff = """
8-
Line 176: Expected 1 errors
9-
Line 194: Expected 1 errors
10-
Line 193: Unexpected errors ['callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]']
8+
Line 184: Expected 1 errors
119
"""
1210
output = """
1311
callables_kwargs.py:47: error: Missing named argument "v1" for "func1" [call-arg]
@@ -30,6 +28,5 @@ callables_kwargs.py:104: error: Incompatible types in assignment (expression has
3028
callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc]
3129
callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc]
3230
callables_kwargs.py:135: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol6") [assignment]
33-
callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]
34-
callables_kwargs.py:195: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD6"; expected "str" [arg-type]
31+
callables_kwargs.py:185: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD5"; expected "str" [arg-type]
3532
"""

‎conformance/tests/callables_kwargs.py‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,11 @@ class TD3(TypedDict):
142142
name: str
143143

144144

145-
class TD4(TypedDict, closed=False):
145+
class TD4(TypedDict, closed=True):
146146
name: str
147147

148148

149-
class TD5(TypedDict, closed=True):
150-
name: str
151-
152-
153-
class TD6(TypedDict, extra_items=int):
149+
class TD5(TypedDict, extra_items=int):
154150
name: str
155151

156152

@@ -163,21 +159,15 @@ def takes_name_kwargs(name: str, **kwargs) -> None:
163159

164160

165161
# > It is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict``
166-
# > to another function if that function has ``**kwargs`` in its signature as well. In this situation,
167-
# > type checkers should error if the ``TypedDict`` is explicitly open (``closed=False``) or has ``extra_items``.
168-
# > Additionally, type checkers may error if the ``TypedDict`` is implicitly open.
162+
# > to another function if that function has ``**kwargs`` in its signature as well. Type checkers
163+
# > should error if the ``TypedDict`` has ``extra_items``, and may error if the ``TypedDict`` is open.
169164

170165
def func8(**kwargs: Unpack[TD3]) -> None:
171166
takes_name(**kwargs) # E?: a subtype may contain unknown keys
172167
takes_name_kwargs(**kwargs)
173168

174169

175170
def func9(**kwargs: Unpack[TD4]) -> None:
176-
takes_name(**kwargs) # E: a subtype may contain unknown keys
177-
takes_name_kwargs(**kwargs)
178-
179-
180-
def func10(**kwargs: Unpack[TD5]) -> None:
181171
takes_name(**kwargs)
182172
takes_name_kwargs(**kwargs)
183173

@@ -190,7 +180,7 @@ def takes_name_int_kwargs(name: str, **kwargs: int) -> None:
190180
...
191181

192182

193-
def func10(**kwargs: Unpack[TD6]) -> None:
183+
def func10(**kwargs: Unpack[TD5]) -> None:
194184
takes_name(**kwargs) # E: extra items may be present
195185
takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible
196186
takes_name_int_kwargs(**kwargs)

‎docs/spec/callables.rst‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,9 @@ it needs completely ignoring any additional values.
413413
The calls to ``bar`` and ``spam`` will fail because an unexpected keyword
414414
argument will be passed to the ``takes_name`` function.
415415

416-
Therefore, it is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict``
417-
to another function if that function has ``**kwargs`` in its signature as well. In this situation,
418-
type checkers should error if the ``TypedDict`` is explicitly open (``closed=False``) or has ``extra_items``.
419-
Additionally, type checkers may error if the ``TypedDict`` is implicitly open.
416+
Therefore, it is only safe to pass ``kwargs`` hinted with an unpacked, non-:term:`closed` ``TypedDict``
417+
to another function if that function has ``**kwargs`` in its signature as well. Type checkers should
418+
error if the ``TypedDict`` has :term:`extra items`, and may error if the ``TypedDict`` is :term:`open`.
420419

421420
In cases similar to the ``bar`` function above the problem could be worked
422421
around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired

0 commit comments

Comments
 (0)