From 410c1c8e9f1d16755193de744b42effce82f2b11 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Mon, 10 Aug 2026 21:16:52 -0400 Subject: [PATCH 01/16] update typeddict kwarg forwarding test --- .../results/mypy/callables_kwargs.toml | 51 +- .../results/pycroscope/callables_kwargs.toml | 39 +- .../results/pyrefly/callables_kwargs.toml | 46 +- .../results/pyright/callables_kwargs.toml | 46 +- conformance/results/results.html | 591 +++++++++++++----- conformance/results/ty/callables_kwargs.toml | 39 +- .../results/zuban/callables_kwargs.toml | 50 +- conformance/tests/callables_kwargs.py | 55 +- docs/spec/callables.rst | 6 +- 9 files changed, 654 insertions(+), 269 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index d34b72732..4d8f7d5b0 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -1,29 +1,40 @@ conformant = "Partial" notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. +Does not support the `closed` and `extra_items` TypedDict class arguments. +Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. +Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. """ output = """ -callables_kwargs.py:46: error: Missing named argument "v1" for "func1" [call-arg] -callables_kwargs.py:46: error: Missing named argument "v3" for "func1" [call-arg] -callables_kwargs.py:51: error: Unexpected keyword argument "v4" for "func1" [call-arg] -callables_kwargs.py:52: error: Too many positional arguments for "func1" [call-arg] -callables_kwargs.py:58: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] -callables_kwargs.py:61: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "int" [arg-type] -callables_kwargs.py:61: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "str" [arg-type] -callables_kwargs.py:63: error: "func1" gets multiple values for keyword argument "v1" [misc] -callables_kwargs.py:64: error: "func2" gets multiple values for keyword argument "v3" [misc] -callables_kwargs.py:64: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] -callables_kwargs.py:65: error: "func2" gets multiple values for keyword argument "v1" [misc] -callables_kwargs.py:101: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol3") [assignment] -callables_kwargs.py:101: note: "TDProtocol3.__call__" has type "def __call__(self, *, v1: int, v2: int, v3: str) -> None" -callables_kwargs.py:102: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol4") [assignment] -callables_kwargs.py:102: note: "TDProtocol4.__call__" has type "def __call__(self, *, v1: int) -> None" -callables_kwargs.py:103: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol5") [assignment] -callables_kwargs.py:103: note: "TDProtocol5.__call__" has type "def __call__(self, v1: int, v3: str) -> None" -callables_kwargs.py:111: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] -callables_kwargs.py:122: error: Unpack item in ** parameter must be a TypedDict [misc] +callables_kwargs.py:47: error: Missing named argument "v1" for "func1" [call-arg] +callables_kwargs.py:47: error: Missing named argument "v3" for "func1" [call-arg] +callables_kwargs.py:52: error: Unexpected keyword argument "v4" for "func1" [call-arg] +callables_kwargs.py:53: error: Too many positional arguments for "func1" [misc] +callables_kwargs.py:59: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] +callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "int" [arg-type] +callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "str" [arg-type] +callables_kwargs.py:64: error: "func1" gets multiple values for keyword argument "v1" [misc] +callables_kwargs.py:65: error: "func2" gets multiple values for keyword argument "v3" [misc] +callables_kwargs.py:65: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] +callables_kwargs.py:66: error: "func2" gets multiple values for keyword argument "v1" [misc] +callables_kwargs.py:102: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol3") [assignment] +callables_kwargs.py:102: note: "TDProtocol3.__call__" has type "def __call__(self, *, v1: int, v2: int, v3: str) -> None" +callables_kwargs.py:103: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol4") [assignment] +callables_kwargs.py:103: note: "TDProtocol4.__call__" has type "def __call__(self, *, v1: int) -> None" +callables_kwargs.py:104: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol5") [assignment] +callables_kwargs.py:104: note: "TDProtocol5.__call__" has type "def __call__(self, v1: int, v3: str) -> None" +callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] +callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] +callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] """ conformance_automated = "Fail" errors_diff = """ -Line 134: Expected 1 errors +Line 135: Expected 1 errors +Line 167: Expected 1 errors +Line 185: Expected 1 errors +Line 186: Expected 1 errors +Line 145: Unexpected errors ['callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] """ diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 492f041f5..a9d595e10 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -1,19 +1,28 @@ -conformance_automated = "Pass" +conformant = "Partial" +notes = """ +Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. +Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. +""" +conformance_automated = "Fail" errors_diff = """ +Line 167: Expected 1 errors +Line 185: Expected 1 errors +Line 186: Expected 1 errors """ output = """ -./callables_kwargs.py:46:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] -./callables_kwargs.py:51:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] -./callables_kwargs.py:52:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] -./callables_kwargs.py:58:4: Incompatible argument type for v1: expected int but got str [incompatible_argument] -./callables_kwargs.py:61:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] -./callables_kwargs.py:63:4: Multiple values provided for argument 'v1' [incompatible_call] -./callables_kwargs.py:64:4: In call to callables_kwargs.func2: Parameter 'v3' provided as both a positional and a keyword argument [incompatible_call] -./callables_kwargs.py:65:4: Multiple values provided for argument 'v1' [incompatible_call] -./callables_kwargs.py:101:0: Incompatible assignment: expected callables_kwargs.TDProtocol3, got function 'callables_kwargs.func1' [incompatible_assignment] -./callables_kwargs.py:102:0: Incompatible assignment: expected callables_kwargs.TDProtocol4, got function 'callables_kwargs.func1' [incompatible_assignment] -./callables_kwargs.py:103:0: Incompatible assignment: expected callables_kwargs.TDProtocol5, got function 'callables_kwargs.func1' [incompatible_assignment] -./callables_kwargs.py:111:21: Parameter v1 overlaps with TypedDict key in **kwargs [invalid_annotation] -./callables_kwargs.py:122:12: Expected TypedDict type inside Unpack[] for **kwargs [invalid_annotation] -./callables_kwargs.py:134:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] +./callables_kwargs.py:47:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] +./callables_kwargs.py:52:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] +./callables_kwargs.py:53:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] +./callables_kwargs.py:59:4: Incompatible argument type for v1: expected int but got str [incompatible_argument] +./callables_kwargs.py:62:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] +./callables_kwargs.py:64:4: Multiple values provided for argument 'v1' [incompatible_call] +./callables_kwargs.py:65:4: In call to callables_kwargs.func2: Parameter 'v3' provided as both a positional and a keyword argument [incompatible_call] +./callables_kwargs.py:66:4: Multiple values provided for argument 'v1' [incompatible_call] +./callables_kwargs.py:102:0: Incompatible assignment: expected callables_kwargs.TDProtocol3, got function 'callables_kwargs.func1' [incompatible_assignment] +./callables_kwargs.py:103:0: Incompatible assignment: expected callables_kwargs.TDProtocol4, got function 'callables_kwargs.func1' [incompatible_assignment] +./callables_kwargs.py:104:0: Incompatible assignment: expected callables_kwargs.TDProtocol5, got function 'callables_kwargs.func1' [incompatible_assignment] +./callables_kwargs.py:112:21: Parameter v1 overlaps with TypedDict key in **kwargs [invalid_annotation] +./callables_kwargs.py:123:12: Expected TypedDict type inside Unpack[] for **kwargs [invalid_annotation] +./callables_kwargs.py:135:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index d37554ce3..c268ef9ca 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -1,23 +1,31 @@ -conformant = "Pass" -conformance_automated = "Pass" +conformant = "Partial" +notes = """ +Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. +Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. +""" +conformance_automated = "Fail" errors_diff = """ +Line 167: Expected 1 errors +Line 185: Expected 1 errors +Line 186: Expected 1 errors """ output = """ -ERROR callables_kwargs.py:46:10-12: Missing argument `v1` in function `func1` [missing-argument] -ERROR callables_kwargs.py:46:10-12: Missing argument `v3` in function `func1` [missing-argument] -ERROR callables_kwargs.py:51:32-34: Unexpected keyword argument `v4` in function `func1` [unexpected-keyword] -ERROR callables_kwargs.py:52:11-12: Expected argument `v1` to be passed by name in function `func1` [unexpected-positional-argument] -ERROR callables_kwargs.py:52:11-12: Expected 0 positional arguments, got 3 in function `func1` [bad-argument-count] -ERROR callables_kwargs.py:52:14-16: Expected argument `v3` to be passed by name in function `func1` [unexpected-positional-argument] -ERROR callables_kwargs.py:58:11-20: Unpacked keyword argument `str` is not assignable to parameter `v1` with type `int` in function `func1` [bad-argument-type] -ERROR callables_kwargs.py:63:17-22: Multiple values for argument `v1` in function `func1` [bad-keyword-argument] -ERROR callables_kwargs.py:64:11-12: Argument `Literal[1]` is not assignable to parameter `v3` with type `str` in function `func2` [bad-argument-type] -ERROR callables_kwargs.py:64:14-19: Multiple values for argument `v3` in function `func2` [bad-keyword-argument] -ERROR callables_kwargs.py:65:17-22: Multiple values for argument `v1` in function `func2` [bad-keyword-argument] -ERROR callables_kwargs.py:101:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol3` [bad-assignment] -ERROR callables_kwargs.py:102:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol4` [bad-assignment] -ERROR callables_kwargs.py:103:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol5` [bad-assignment] -ERROR callables_kwargs.py:111:20-41: TypedDict key 'v1' in **kwargs overlaps with parameter 'v1' [bad-function-definition] -ERROR callables_kwargs.py:122:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] -ERROR callables_kwargs.py:134:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] +ERROR callables_kwargs.py:47:10-12: Missing argument `v1` in function `func1` [missing-argument] +ERROR callables_kwargs.py:47:10-12: Missing argument `v3` in function `func1` [missing-argument] +ERROR callables_kwargs.py:52:32-34: Unexpected keyword argument `v4` in function `func1` [unexpected-keyword] +ERROR callables_kwargs.py:53:11-12: Expected argument `v1` to be passed by name in function `func1` [unexpected-positional-argument] +ERROR callables_kwargs.py:53:11-12: Expected 0 positional arguments, got 3 in function `func1` [bad-argument-count] +ERROR callables_kwargs.py:53:14-16: Expected argument `v3` to be passed by name in function `func1` [unexpected-positional-argument] +ERROR callables_kwargs.py:59:11-20: Unpacked keyword argument `str` is not assignable to parameter `v1` with type `int` in function `func1` [bad-argument-type] +ERROR callables_kwargs.py:64:17-22: Multiple values for argument `v1` in function `func1` [bad-keyword-argument] +ERROR callables_kwargs.py:65:11-12: Argument `Literal[1]` is not assignable to parameter `v3` with type `str` in function `func2` [bad-argument-type] +ERROR callables_kwargs.py:65:14-19: Multiple values for argument `v3` in function `func2` [bad-keyword-argument] +ERROR callables_kwargs.py:66:17-22: Multiple values for argument `v1` in function `func2` [bad-keyword-argument] +ERROR callables_kwargs.py:102:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol3` [bad-assignment] +ERROR callables_kwargs.py:103:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol4` [bad-assignment] +ERROR callables_kwargs.py:104:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol5` [bad-assignment] +ERROR callables_kwargs.py:112:20-41: TypedDict key 'v1' in **kwargs overlaps with parameter 'v1' [bad-function-definition] +ERROR callables_kwargs.py:123:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] +ERROR callables_kwargs.py:135:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index b04d6a66a..8cc86c821 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -1,36 +1,44 @@ -conformant = "Pass" +conformant = "Partial" +notes = """ +Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. +Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +""" output = """ -callables_kwargs.py:28:5 - error: Could not access item in TypedDict +callables_kwargs.py:29:5 - error: Could not access item in TypedDict   "v2" is not a required key in "TD2", so access may result in runtime exception (reportTypedDictNotRequiredAccess) -callables_kwargs.py:46:5 - error: Arguments missing for parameters "v1", "v3" (reportCallIssue) -callables_kwargs.py:51:32 - error: No parameter named "v4" (reportCallIssue) -callables_kwargs.py:52:11 - error: Expected 0 positional arguments (reportCallIssue) -callables_kwargs.py:58:13 - error: Argument of type "str" cannot be assigned to parameter "v1" of type "int" in function "func1" +callables_kwargs.py:47:5 - error: Arguments missing for parameters "v1", "v3" (reportCallIssue) +callables_kwargs.py:52:32 - error: No parameter named "v4" (reportCallIssue) +callables_kwargs.py:53:11 - error: Expected 0 positional arguments (reportCallIssue) +callables_kwargs.py:59:13 - error: Argument of type "str" cannot be assigned to parameter "v1" of type "int" in function "func1"   "str" is not assignable to "int" (reportArgumentType) -callables_kwargs.py:63:19 - error: Unable to match unpacked TypedDict argument to parameters +callables_kwargs.py:64:19 - error: Unable to match unpacked TypedDict argument to parameters   Parameter "v1" is already assigned (reportCallIssue) -callables_kwargs.py:64:16 - error: Unable to match unpacked TypedDict argument to parameters +callables_kwargs.py:65:16 - error: Unable to match unpacked TypedDict argument to parameters   Parameter "v3" is already assigned (reportCallIssue) -callables_kwargs.py:65:19 - error: Unable to match unpacked TypedDict argument to parameters +callables_kwargs.py:66:19 - error: Unable to match unpacked TypedDict argument to parameters   Parameter "v1" is already assigned (reportCallIssue) -callables_kwargs.py:101:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol3" +callables_kwargs.py:102:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol3"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(*, v1: int, v2: int, v3: str) -> None"     Keyword parameter "v2" of type "int" is incompatible with type "str"       "int" is not assignable to "str" (reportAssignmentType) -callables_kwargs.py:102:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol4" +callables_kwargs.py:103:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol4"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(*, v1: int) -> None"     Extra parameter "v3" (reportAssignmentType) -callables_kwargs.py:103:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol5" +callables_kwargs.py:104:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol5"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(v1: int, v3: str) -> None" -    Function accepts too few positional parameters; expected 2 but received 0 -      Parameter "v1" is missing default argument -      Parameter "v3" is missing default argument (reportAssignmentType) -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) -callables_kwargs.py:134:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6" +    Function accepts too many positional parameters; expected 0 but received 2 +      Extra parameter "v1" +      Extra parameter "v3" (reportAssignmentType) +callables_kwargs.py:112:30 - error: Typed dictionary overlaps with keyword parameter: v1 (reportGeneralTypeIssues) +callables_kwargs.py:123:21 - error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues) +callables_kwargs.py:135:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) +callables_kwargs.py:186:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "int" is not assignable to "str" (reportArgumentType) """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 167: Expected 1 errors +Line 185: Expected 1 errors """ diff --git a/conformance/results/results.html b/conformance/results/results.html index e4c61d5d3..9a260d9dc 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -264,12 +264,12 @@

Python Type System Conformance Test Results

- mypy 2.4.0 - pycroscope 0.5.0 - pyrefly 1.5.0 - pyright 1.1.414 - ty 0.0.108 - zuban 0.10.2 + mypy 2.1.0 + pycroscope 0.4.0 + pyrefly 1.3.0-dev.1 + pyright 1.1.410 + ty 0.0.70 + zuban 0.8.2 @@ -294,52 +294,36 @@

Python Type System Conformance Test Results

Partial - Pass Partial Pass - Pass - - - annotations_future_import - - Partial - - Partial - Pass Partial - Pass - Pass annotations_generators @@ -390,12 +374,12 @@

Python Type System Conformance Test Results

- 4.5 / 6 • 75.0% - 4.5 / 6 • 75.0% - 6 / 6 • 100.0% - 5 / 6 • 83.3% - 6 / 6 • 100.0% - 6 / 6 • 100.0% + 4 / 5 • 80.0% + 4 / 5 • 80.0% + 4.5 / 5 • 90.0% + 5 / 5 • 100.0% + 4.5 / 5 • 90.0% + 4.5 / 5 • 90.0% @@ -419,7 +403,7 @@

Python Type System Conformance Test Results

Pass - Pass + Unsupported Pass Pass @@ -428,7 +412,7 @@

Python Type System Conformance Test Results

0.5 / 1 • 50.0% 0.5 / 1 • 50.0% 1 / 1 • 100.0% - 1 / 1 • 100.0% + 0 / 1 • 0.0% 1 / 1 • 100.0% 1 / 1 • 100.0% @@ -483,7 +467,7 @@

Python Type System Conformance Test Results

specialtypes_sentinels - Pass + Unsupported Pass Pass @@ -511,6 +495,7 @@

Python Type System Conformance Test Results

Partial @@ -518,7 +503,7 @@

Python Type System Conformance Test Results

- 5.5 / 6 • 91.7% + 4.5 / 6 • 75.0% 5.5 / 6 • 91.7% 6 / 6 • 100.0% 5.5 / 6 • 91.7% @@ -552,7 +537,12 @@

Python Type System Conformance Test Results

Pass Pass Pass - Pass + + Partial + + Pass @@ -564,10 +554,22 @@

Python Type System Conformance Test Results

  • Does not fully support defaults on TypeVarTuple and ParamSpec.
  • + + Partial + + Pass Pass - Pass - Pass + + Partial + + Pass @@ -578,7 +580,12 @@

    Python Type System Conformance Test Results

  • Does not correctly handle defaults referencing other TypeVars.
  • - Pass + + Partial + + Pass Pass Pass @@ -586,21 +593,36 @@

    Python Type System Conformance Test Results

    generics_defaults_specialization + + Partial + + Pass Pass - Pass - Pass + + Partial + + Pass Pass generics_mixed_variance_inference Pass - Pass - Pass + Unsupported + Unsupported Unsupported Pass - Pass + + Partial + + generics_paramspec_basic @@ -646,11 +668,16 @@

    Python Type System Conformance Test Results

    generics_paramspec_variance Unsupported - Pass - Pass Unsupported - Pass - Pass + Unsupported + Unsupported + + Partial + + + Unsupported generics_scoping @@ -658,7 +685,13 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass @@ -730,12 +763,7 @@

    Python Type System Conformance Test Results

    generics_syntax_declarations - - Partial - - + Pass Pass Pass Pass @@ -764,7 +792,12 @@

    Python Type System Conformance Test Results

  • Does not following runtime scoping rules for type parameters in all cases.
  • - Pass + + Partial + + Pass Pass Pass @@ -776,12 +809,18 @@

    Python Type System Conformance Test Results

    Partial Pass Pass Pass - Pass + + Partial + + Pass @@ -794,8 +833,18 @@

    Python Type System Conformance Test Results

    Pass Pass - Pass - Pass + + Partial + + + + Partial + + Pass @@ -806,9 +855,19 @@

    Python Type System Conformance Test Results

  • Does not enforce that tuples captured by TypeVarTuple are same length.
  • + + Partial + + Pass - Pass - Pass + + Partial + + Pass Pass @@ -818,7 +877,12 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass @@ -866,11 +930,16 @@

    Python Type System Conformance Test Results

    generics_typevartuple_variance Unsupported - Pass - Pass Unsupported - Pass - Pass + Unsupported + Unsupported + + Partial + + + Unsupported generics_upper_bound @@ -914,16 +983,23 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + 23.5 / 33 • 71.2% - 33 / 33 • 100.0% - 33 / 33 • 100.0% + 28 / 33 • 84.8% + 30 / 33 • 90.9% + 28.5 / 33 • 86.4% + 29 / 33 • 87.9% 30 / 33 • 90.9% - 33 / 33 • 100.0% - 33 / 33 • 100.0% @@ -1009,7 +1085,12 @@

    Python Type System Conformance Test Results

  • Does not reject use of ClassVar in TypeAlias definition.
  • - Pass + + Partial + + Pass Pass Pass @@ -1024,8 +1105,6 @@

    Python Type System Conformance Test Results

  • the incompatible constructor overrides in ChildC2 are not flagged.
  • - Pass - Pass Partial Pass - Pass + + Partial + + + + Partial + + + + Partial + + 1 / 2 • 50.0% - 2 / 2 • 100.0% + 1 / 2 • 50.0% 2 / 2 • 100.0% 1.5 / 2 • 75.0% - 2 / 2 • 100.0% - 2 / 2 • 100.0% + 1.5 / 2 • 75.0% + 1.5 / 2 • 75.0% @@ -1063,7 +1162,12 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass @@ -1078,7 +1182,13 @@

    Python Type System Conformance Test Results

    Pass Pass - Pass + + Partial + + Pass @@ -1101,7 +1211,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + Unsupported Pass @@ -1111,12 +1221,16 @@

    Python Type System Conformance Test Results

    Partial Pass Pass - Pass + + Partial + + Pass @@ -1128,10 +1242,20 @@

    Python Type System Conformance Test Results

  • Incorrectly rejects the use of a class-scoped TypeVar in a TypeAliasType definition.
  • + + Partial + + Pass Pass - Pass - Pass + + Partial + + Pass @@ -1146,10 +1270,10 @@

    Python Type System Conformance Test Results

    5.5 / 7 • 78.6% - 6 / 7 • 85.7% - 7 / 7 • 100.0% + 5.5 / 7 • 78.6% 7 / 7 • 100.0% 7 / 7 • 100.0% + 4 / 7 • 57.1% 7 / 7 • 100.0% @@ -1260,7 +1384,12 @@

    Python Type System Conformance Test Results

  • Does not detect protocol mismatch if concrete method's parameters are position-only.
  • - Pass + + Partial + + Pass Pass Pass @@ -1277,11 +1406,11 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial + + Unsupported Pass @@ -1292,6 +1421,7 @@

    Python Type System Conformance Test Results

    Partial @@ -1300,7 +1430,7 @@

    Python Type System Conformance Test Results

    Partial Pass @@ -1311,7 +1441,12 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass @@ -1383,24 +1518,34 @@

    Python Type System Conformance Test Results

    Pass - Pass + + Partial + + Partial - Pass - Pass + Unsupported + + Partial + + 9.5 / 11 • 86.4% - 10 / 11 • 90.9% - 11 / 11 • 100.0% + 9.5 / 11 • 86.4% + 10.5 / 11 • 95.5% + 10.5 / 11 • 95.5% + 6.5 / 11 • 59.1% 10.5 / 11 • 95.5% - 8.5 / 11 • 77.3% - 11 / 11 • 100.0% @@ -1418,7 +1563,12 @@

    Python Type System Conformance Test Results

  • Does not treat *args: Any, **kargs: Any as ... when separated by keyword parameter.
  • - Pass + + Partial + + Pass Pass Pass @@ -1430,18 +1580,58 @@

    Python Type System Conformance Test Results

    Partial + + + Partial + + + + Partial + + + + Partial + + + + Partial + + + + Partial + - Pass - Pass - Pass - Pass - Pass callables_protocol Pass - Pass + + Partial + + Pass Pass Pass @@ -1450,7 +1640,12 @@

    Python Type System Conformance Test Results

    callables_subtyping Pass - Pass + + Partial + + Pass Pass Pass @@ -1459,11 +1654,11 @@

    Python Type System Conformance Test Results

    3 / 4 • 75.0% - 4 / 4 • 100.0% - 4 / 4 • 100.0% - 4 / 4 • 100.0% - 4 / 4 • 100.0% - 4 / 4 • 100.0% + 2 / 4 • 50.0% + 3.5 / 4 • 87.5% + 3.5 / 4 • 87.5% + 3.5 / 4 • 87.5% + 3.5 / 4 • 87.5% @@ -1488,6 +1683,7 @@

    Python Type System Conformance Test Results

    Partial Pass @@ -1654,12 +1850,18 @@

    Python Type System Conformance Test Results

  • 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 evaluate Any in some cases where overload is ambiguous.
  • Evaluates Any in some cases where overload is not ambiguous.
  • Pass Pass - Pass + + Partial + + Pass Pass @@ -1668,7 +1870,7 @@

    Python Type System Conformance Test Results

    3.5 / 5 • 70.0% 3.5 / 5 • 70.0% 5 / 5 • 100.0% - 5 / 5 • 100.0% + 4.5 / 5 • 90.0% 5 / 5 • 100.0% 5 / 5 • 100.0% @@ -1685,7 +1887,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + Unsupported Pass @@ -1694,7 +1896,7 @@

    Python Type System Conformance Test Results

    1 / 1 • 100.0% 1 / 1 • 100.0% 1 / 1 • 100.0% - 1 / 1 • 100.0% + 0 / 1 • 0.0% 1 / 1 • 100.0% @@ -1706,11 +1908,33 @@

    Python Type System Conformance Test Results

    dataclasses_descriptors + + Partial + + + + Partial + + + + Partial + + Pass - Pass - Pass - Pass - Pass + + Partial + + Pass @@ -1809,7 +2033,12 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass @@ -1889,11 +2118,11 @@

    Python Type System Conformance Test Results

    - 12 / 16 • 75.0% - 16 / 16 • 100.0% - 16 / 16 • 100.0% - 16 / 16 • 100.0% + 11.5 / 16 • 71.9% + 15.5 / 16 • 96.9% + 15.5 / 16 • 96.9% 16 / 16 • 100.0% + 15 / 16 • 93.8% 16 / 16 • 100.0% @@ -1927,7 +2156,12 @@

    Python Type System Conformance Test Results

    Pass Pass - Pass + + Partial + + Pass Pass @@ -2037,7 +2271,12 @@

    Python Type System Conformance Test Results

    typeddicts_type_consistency Pass - Pass + + Partial + + Pass Pass Pass @@ -2055,9 +2294,9 @@

    Python Type System Conformance Test Results

    11.5 / 14 • 82.1% + 13.5 / 14 • 96.4% 14 / 14 • 100.0% - 14 / 14 • 100.0% - 14 / 14 • 100.0% + 13.5 / 14 • 96.4% 14 / 14 • 100.0% 14 / 14 • 100.0% @@ -2131,7 +2370,12 @@

    Python Type System Conformance Test Results

  • Does not support version-conditional fields.
  • - Pass + + Partial + + Pass Pass Pass @@ -2172,7 +2416,7 @@

    Python Type System Conformance Test Results

    3 / 4 • 75.0% - 4 / 4 • 100.0% + 3.5 / 4 • 87.5% 4 / 4 • 100.0% 4 / 4 • 100.0% 4 / 4 • 100.0% @@ -2197,7 +2441,12 @@

    Python Type System Conformance Test Results

    enums_definition Pass - Pass + + Partial + + Pass Pass Pass @@ -2213,9 +2462,19 @@

    Python Type System Conformance Test Results

    Pass Pass + + Partial + + Pass - Pass - Pass + + Partial + + enums_member_names @@ -2273,11 +2532,11 @@

    Python Type System Conformance Test Results

    4.5 / 6 • 75.0% + 5.5 / 6 • 91.7% 6 / 6 • 100.0% + 5.5 / 6 • 91.7% 6 / 6 • 100.0% - 6 / 6 • 100.0% - 6 / 6 • 100.0% - 6 / 6 • 100.0% + 5.5 / 6 • 91.7% @@ -2301,7 +2560,12 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass @@ -2310,7 +2574,7 @@

    Python Type System Conformance Test Results

    2 / 2 • 100.0% 2 / 2 • 100.0% 2 / 2 • 100.0% - 2 / 2 • 100.0% + 1.5 / 2 • 75.0% 2 / 2 • 100.0% @@ -2344,15 +2608,32 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Pass + + Partial + + Pass directives_disjoint_base Pass + + Partial + + Pass - Pass - Pass + + Unsupported + + Pass Pass @@ -2444,10 +2725,10 @@

    Python Type System Conformance Test Results

    10 / 11 • 90.9% + 10.5 / 11 • 95.5% 11 / 11 • 100.0% - 11 / 11 • 100.0% - 11 / 11 • 100.0% - 11 / 11 • 100.0% + 10 / 11 • 90.9% + 10.5 / 11 • 95.5% 11 / 11 • 100.0% @@ -2486,12 +2767,12 @@

    Python Type System Conformance Test Results

    - 110.5 / 146 • 75.7% - 139 / 146 • 95.2% - 146 / 146 • 100.0% - 140.5 / 146 • 96.2% - 142 / 146 • 97.3% - 146 / 146 • 100.0% + 108.5 / 145 • 74.8% + 127 / 145 • 87.6% + 140 / 145 • 96.6% + 135 / 145 • 93.1% + 127.5 / 145 • 87.9% + 139.5 / 145 • 96.2% diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 3318d6bb6..6f9c4395a 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -1,20 +1,27 @@ -conformance_automated = "Pass" +conformant = "Partial" +notes = """ +Does not reject passing unpacked kwargs typed with an open TypedDict to a callable that has no `**kwargs`. +""" +conformance_automated = "Fail" errors_diff = """ +Line 167: Expected 1 errors """ output = """ -callables_kwargs.py:46:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` -callables_kwargs.py:52:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` -callables_kwargs.py:52:11: error[too-many-positional-arguments] Too many positional arguments to function `func1`: expected 0, got 3 -callables_kwargs.py:58:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `int`, found `str` -callables_kwargs.py:61:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `str`, found `int | str` -callables_kwargs.py:63:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func1` -callables_kwargs.py:64:11: error[invalid-argument-type] Argument to function `func2` is incorrect: Expected `str`, found `Literal[1]` -callables_kwargs.py:64:14: error[parameter-already-assigned] Multiple values provided for parameter `v3` of function `func2` -callables_kwargs.py:65:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func2` -callables_kwargs.py:101:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol3` -callables_kwargs.py:102:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol4` -callables_kwargs.py:103:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol5` -callables_kwargs.py:111:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation -callables_kwargs.py:122:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` -callables_kwargs.py:134:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6` +callables_kwargs.py:47:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` +callables_kwargs.py:53:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` +callables_kwargs.py:53:11: error[too-many-positional-arguments] Too many positional arguments to function `func1`: expected 0, got 3 +callables_kwargs.py:59:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `int`, found `str` +callables_kwargs.py:62:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `str`, found `int | str` +callables_kwargs.py:64:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func1` +callables_kwargs.py:65:11: error[invalid-argument-type] Argument to function `func2` is incorrect: Expected `str`, found `Literal[1]` +callables_kwargs.py:65:14: error[parameter-already-assigned] Multiple values provided for parameter `v3` of function `func2` +callables_kwargs.py:66:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func2` +callables_kwargs.py:102:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol3` +callables_kwargs.py:103:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol4` +callables_kwargs.py:104:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol5` +callables_kwargs.py:112:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation +callables_kwargs.py:123:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` +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` +callables_kwargs.py:185:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:186:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 678f5d318..8d57e8090 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -1,25 +1,33 @@ -conformance_automated = "Pass" +conformant = "Partial" +notes = """ +Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. +Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +""" +conformance_automated = "Fail" errors_diff = """ +Line 167: Expected 1 errors +Line 185: Expected 1 errors """ output = """ -callables_kwargs.py:46: error: Missing named argument "v1" for "func1" [call-arg] -callables_kwargs.py:46: error: Missing named argument "v3" for "func1" [call-arg] -callables_kwargs.py:51: error: Unexpected keyword argument "v4" for "func1" [call-arg] -callables_kwargs.py:52: error: Too many positional arguments for "func1" [call-arg] -callables_kwargs.py:52: error: Missing named argument "v1" for "func1" [call-arg] -callables_kwargs.py:52: error: Missing named argument "v3" for "func1" [call-arg] -callables_kwargs.py:58: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] -callables_kwargs.py:61: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "int" [arg-type] -callables_kwargs.py:61: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] -callables_kwargs.py:61: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] -callables_kwargs.py:63: error: "func1" gets multiple values for keyword argument "v1" [call-arg] -callables_kwargs.py:64: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] -callables_kwargs.py:64: error: "func2" gets multiple values for keyword argument "v3" [call-arg] -callables_kwargs.py:65: error: "func2" gets multiple values for keyword argument "v1" [call-arg] -callables_kwargs.py:101: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol3") [assignment] -callables_kwargs.py:102: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol4") [assignment] -callables_kwargs.py:103: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol5") [assignment] -callables_kwargs.py:111: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] -callables_kwargs.py:122: error: Unpack item in ** parameter must be a TypedDict [misc] -callables_kwargs.py:134: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol6") [assignment] +callables_kwargs.py:47: error: Missing named argument "v1" for "func1" [call-arg] +callables_kwargs.py:47: error: Missing named argument "v3" for "func1" [call-arg] +callables_kwargs.py:52: error: Unexpected keyword argument "v4" for "func1" [call-arg] +callables_kwargs.py:53: error: Too many positional arguments for "func1" [call-arg] +callables_kwargs.py:53: error: Missing named argument "v1" for "func1" [call-arg] +callables_kwargs.py:53: error: Missing named argument "v3" for "func1" [call-arg] +callables_kwargs.py:59: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] +callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "int" [arg-type] +callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] +callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] +callables_kwargs.py:64: error: "func1" gets multiple values for keyword argument "v1" [call-arg] +callables_kwargs.py:65: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] +callables_kwargs.py:65: error: "func2" gets multiple values for keyword argument "v3" [call-arg] +callables_kwargs.py:66: error: "func2" gets multiple values for keyword argument "v1" [call-arg] +callables_kwargs.py:102: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol3") [assignment] +callables_kwargs.py:103: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol4") [assignment] +callables_kwargs.py:104: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol5") [assignment] +callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] +callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] +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] +callables_kwargs.py:186: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD5"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index a4c431dbd..58d165c84 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -7,7 +7,8 @@ # This sample tests the handling of Unpack[TypedDict] when used with # a **kwargs parameter in a function signature. -from typing import Protocol, TypeVar, TypedDict, NotRequired, Required, Unpack, assert_type +from typing import Protocol, TypeVar, NotRequired, Required, Unpack, assert_type +from typing_extensions import TypedDict # for the `closed` and `extra_items` arguments class TD1(TypedDict): @@ -132,3 +133,55 @@ def func7(*, v1: int, v3: str, v2: str = "") -> None: v7: TDProtocol6 = func7 # E: source does not have kwargs + + +# Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#passing-kwargs-inside-a-function-to-another-function + + +class TD3(TypedDict): + name: str + + +class TD4(TypedDict, closed=True): + name: str + + +class TD5(TypedDict, extra_items=int): + name: str + + +def takes_name(name: str) -> None: + ... + + +def takes_name_kwargs(name: str, **kwargs) -> None: + ... + + +# > ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` can only +# > be passed to another function if the function to which unpacked kwargs are being +# > passed to has ``**kwargs`` in its signature as well, because then additional +# > keywords would not cause errors at runtime during function invocation. + +def func8(**kwargs: Unpack[TD3]) -> None: + takes_name(**kwargs) # E: a subtype may contain unknown keys + takes_name_kwargs(**kwargs) + + +def func9(**kwargs: Unpack[TD4]) -> None: + takes_name(**kwargs) + takes_name_kwargs(**kwargs) + + +def takes_name_str_kwargs(name: str, **kwargs: str) -> None: + ... + + +def takes_name_int_kwargs(name: str, **kwargs: int) -> None: + ... + + +def func10(**kwargs: Unpack[TD5]) -> None: + takes_name(**kwargs) # E: extra items may be present + takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible + takes_name_int_kwargs(**kwargs) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index f23220400..785b74af0 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -413,15 +413,15 @@ it needs completely ignoring any additional values. The calls to ``bar`` and ``spam`` will fail because an unexpected keyword argument will be passed to the ``takes_name`` function. -Therefore, ``kwargs`` hinted with an unpacked ``TypedDict`` can only be passed +Therefore, ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` can only be passed to another function if the function to which unpacked kwargs are being passed to has ``**kwargs`` in its signature as well, because then additional keywords would not cause errors at runtime during function invocation. Otherwise, the type checker should generate an error. In cases similar to the ``bar`` function above the problem could be worked -around by explicitly dereferencing desired fields and using them as arguments -to perform the function call:: +around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired +fields and using them as arguments to perform the function call:: def bar(**kwargs: Unpack[Animal]): name = kwargs["name"] From 156623e27faab29c84b6579615e6a60ce8ece9a5 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Tue, 11 Aug 2026 23:27:49 -0400 Subject: [PATCH 02/16] update spec wording and results to make erroring on implicitly open TypedDicts optional --- .../results/mypy/callables_kwargs.toml | 14 +++++++---- .../results/pycroscope/callables_kwargs.toml | 6 ++--- .../results/pyrefly/callables_kwargs.toml | 6 ++--- .../results/pyright/callables_kwargs.toml | 8 +++--- conformance/results/ty/callables_kwargs.toml | 6 ++--- .../results/zuban/callables_kwargs.toml | 8 +++--- conformance/tests/callables_kwargs.py | 25 +++++++++++++------ docs/spec/callables.rst | 9 +++---- 8 files changed, 49 insertions(+), 33 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 4d8f7d5b0..030d23629 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -27,14 +27,18 @@ callables_kwargs.py:104: note: "TDProtocol5.__call__" has type "def __call__(sel callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:149: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:153: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef] """ conformance_automated = "Fail" errors_diff = """ Line 135: Expected 1 errors -Line 167: Expected 1 errors -Line 185: Expected 1 errors -Line 186: Expected 1 errors +Line 176: Expected 1 errors +Line 194: Expected 1 errors +Line 195: Expected 1 errors Line 145: Unexpected errors ['callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 153: Unexpected errors ['callables_kwargs.py:153: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 193: Unexpected errors ['callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]'] """ diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index a9d595e10..107baaaff 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -6,9 +6,9 @@ Does not check the `extra_items` type of unpacked kwargs against the target call """ conformance_automated = "Fail" errors_diff = """ -Line 167: Expected 1 errors -Line 185: Expected 1 errors -Line 186: Expected 1 errors +Line 176: Expected 1 errors +Line 194: Expected 1 errors +Line 195: Expected 1 errors """ output = """ ./callables_kwargs.py:47:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index c268ef9ca..bb38eee0b 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -6,9 +6,9 @@ Does not check the `extra_items` type of unpacked kwargs against the target call """ conformance_automated = "Fail" errors_diff = """ -Line 167: Expected 1 errors -Line 185: Expected 1 errors -Line 186: Expected 1 errors +Line 176: Expected 1 errors +Line 194: Expected 1 errors +Line 195: Expected 1 errors """ output = """ ERROR callables_kwargs.py:47:10-12: Missing argument `v1` in function `func1` [missing-argument] diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 8cc86c821..2f5dcf49c 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -34,11 +34,13 @@ callables_kwargs.py:123:21 - error: Expected TypedDict type argument for Unpack callables_kwargs.py:135:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) -callables_kwargs.py:186:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:180:5 - error: Function declaration "func10" is obscured by a declaration of the same name (reportRedeclaration) +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"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 167: Expected 1 errors -Line 185: Expected 1 errors +Line 176: Expected 1 errors +Line 194: Expected 1 errors +Line 180: Unexpected errors ['callables_kwargs.py:180:5 - error: Function declaration "func10" is obscured by a declaration of the same name (reportRedeclaration)'] """ diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 6f9c4395a..8a5170e4e 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -4,7 +4,7 @@ Does not reject passing unpacked kwargs typed with an open TypedDict to a callab """ conformance_automated = "Fail" errors_diff = """ -Line 167: Expected 1 errors +Line 176: Expected 1 errors """ output = """ callables_kwargs.py:47:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` @@ -22,6 +22,6 @@ callables_kwargs.py:104:19: error[invalid-assignment] Object of type `def func1( callables_kwargs.py:112:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation callables_kwargs.py:123:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` 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` -callables_kwargs.py:185:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:186:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +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` +callables_kwargs.py:195:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 8d57e8090..500efa063 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -5,8 +5,9 @@ Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_i """ conformance_automated = "Fail" errors_diff = """ -Line 167: Expected 1 errors -Line 185: Expected 1 errors +Line 176: Expected 1 errors +Line 194: Expected 1 errors +Line 193: Unexpected errors ['callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]'] """ output = """ callables_kwargs.py:47: error: Missing named argument "v1" for "func1" [call-arg] @@ -29,5 +30,6 @@ callables_kwargs.py:104: error: Incompatible types in assignment (expression has callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] 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] -callables_kwargs.py:186: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD5"; expected "str" [arg-type] +callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef] +callables_kwargs.py:195: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD6"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index 58d165c84..22091a618 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -142,11 +142,15 @@ class TD3(TypedDict): name: str -class TD4(TypedDict, closed=True): +class TD4(TypedDict, closed=False): name: str -class TD5(TypedDict, extra_items=int): +class TD5(TypedDict, closed=True): + name: str + + +class TD6(TypedDict, extra_items=int): name: str @@ -158,17 +162,22 @@ def takes_name_kwargs(name: str, **kwargs) -> None: ... -# > ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` can only -# > be passed to another function if the function to which unpacked kwargs are being -# > passed to has ``**kwargs`` in its signature as well, because then additional -# > keywords would not cause errors at runtime during function invocation. +# > It is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` +# > to another function if that function has ``**kwargs`` in its signature as well. In this situation, +# > type checkers should error if the ``TypedDict`` is explicitly open (``closed=False``) or has ``extra_items``. +# > Additionally, type checkers may error if the ``TypedDict`` is implicitly open. def func8(**kwargs: Unpack[TD3]) -> None: - takes_name(**kwargs) # E: a subtype may contain unknown keys + takes_name(**kwargs) # E?: a subtype may contain unknown keys takes_name_kwargs(**kwargs) def func9(**kwargs: Unpack[TD4]) -> None: + takes_name(**kwargs) # E: a subtype may contain unknown keys + takes_name_kwargs(**kwargs) + + +def func10(**kwargs: Unpack[TD5]) -> None: takes_name(**kwargs) takes_name_kwargs(**kwargs) @@ -181,7 +190,7 @@ def takes_name_int_kwargs(name: str, **kwargs: int) -> None: ... -def func10(**kwargs: Unpack[TD5]) -> None: +def func10(**kwargs: Unpack[TD6]) -> None: takes_name(**kwargs) # E: extra items may be present takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible takes_name_int_kwargs(**kwargs) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index 785b74af0..bf4dc383e 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -413,11 +413,10 @@ it needs completely ignoring any additional values. The calls to ``bar`` and ``spam`` will fail because an unexpected keyword argument will be passed to the ``takes_name`` function. -Therefore, ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` can only be passed -to another function if the function to which unpacked kwargs are being passed -to has ``**kwargs`` in its signature as well, because then additional keywords -would not cause errors at runtime during function invocation. Otherwise, the -type checker should generate an error. +Therefore, it is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` +to another function if that function has ``**kwargs`` in its signature as well. In this situation, +type checkers should error if the ``TypedDict`` is explicitly open (``closed=False``) or has ``extra_items``. +Additionally, type checkers may error if the ``TypedDict`` is implicitly open. In cases similar to the ``bar`` function above the problem could be worked around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired From f09c47b9ba5f0262ea54a69f1a8151084c56bcc8 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Thu, 13 Aug 2026 08:19:39 -0400 Subject: [PATCH 03/16] link to terms & handle implicitly open typeddicts the same as explicitly open ones --- .../results/mypy/callables_kwargs.toml | 13 ++++-------- .../results/pycroscope/callables_kwargs.toml | 5 ++--- .../results/pyrefly/callables_kwargs.toml | 5 ++--- .../results/pyright/callables_kwargs.toml | 7 ++----- conformance/results/results.html | 11 +++------- conformance/results/ty/callables_kwargs.toml | 12 ++++------- .../results/zuban/callables_kwargs.toml | 7 ++----- conformance/tests/callables_kwargs.py | 20 +++++-------------- docs/spec/callables.rst | 7 +++---- 9 files changed, 27 insertions(+), 60 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 030d23629..eec7a9a13 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -27,18 +27,13 @@ callables_kwargs.py:104: note: "TDProtocol5.__call__" has type "def __call__(sel callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:149: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:153: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef] +callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] """ conformance_automated = "Fail" errors_diff = """ Line 135: Expected 1 errors -Line 176: Expected 1 errors -Line 194: Expected 1 errors -Line 195: Expected 1 errors +Line 184: Expected 1 errors +Line 185: Expected 1 errors Line 145: Unexpected errors ['callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 153: Unexpected errors ['callables_kwargs.py:153: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 193: Unexpected errors ['callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]'] +Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] """ diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 107baaaff..710649de2 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -6,9 +6,8 @@ Does not check the `extra_items` type of unpacked kwargs against the target call """ conformance_automated = "Fail" errors_diff = """ -Line 176: Expected 1 errors -Line 194: Expected 1 errors -Line 195: Expected 1 errors +Line 184: Expected 1 errors +Line 185: Expected 1 errors """ output = """ ./callables_kwargs.py:47:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index bb38eee0b..666a28973 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -6,9 +6,8 @@ Does not check the `extra_items` type of unpacked kwargs against the target call """ conformance_automated = "Fail" errors_diff = """ -Line 176: Expected 1 errors -Line 194: Expected 1 errors -Line 195: Expected 1 errors +Line 184: Expected 1 errors +Line 185: Expected 1 errors """ output = """ ERROR callables_kwargs.py:47:10-12: Missing argument `v1` in function `func1` [missing-argument] diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 2f5dcf49c..8173c49e4 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -34,13 +34,10 @@ callables_kwargs.py:123:21 - error: Expected TypedDict type argument for Unpack callables_kwargs.py:135:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) -callables_kwargs.py:180:5 - error: Function declaration "func10" is obscured by a declaration of the same name (reportRedeclaration) -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" +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"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 176: Expected 1 errors -Line 194: Expected 1 errors -Line 180: Unexpected errors ['callables_kwargs.py:180:5 - error: Function declaration "func10" is obscured by a declaration of the same name (reportRedeclaration)'] +Line 184: Expected 1 errors """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 9a260d9dc..39a0e2081 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1609,12 +1609,7 @@

    Python Type System Conformance Test Results

  • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
  • - - Partial -
      -
    • Does not reject passing unpacked kwargs typed with an open TypedDict to a callable that has no **kwargs.
    • -
    - + Pass Partial
      @@ -1657,7 +1652,7 @@

      Python Type System Conformance Test Results

      2 / 4 • 50.0% 3.5 / 4 • 87.5% 3.5 / 4 • 87.5% - 3.5 / 4 • 87.5% + 4 / 4 • 100.0% 3.5 / 4 • 87.5% @@ -2771,7 +2766,7 @@

      Python Type System Conformance Test Results

      127 / 145 • 87.6% 140 / 145 • 96.6% 135 / 145 • 93.1% - 127.5 / 145 • 87.9% + 128 / 145 • 88.3% 139.5 / 145 • 96.2% diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 8a5170e4e..44aa885c3 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -1,10 +1,6 @@ -conformant = "Partial" -notes = """ -Does not reject passing unpacked kwargs typed with an open TypedDict to a callable that has no `**kwargs`. -""" -conformance_automated = "Fail" +conformant = "Pass" +conformance_automated = "Pass" errors_diff = """ -Line 176: Expected 1 errors """ output = """ 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( callables_kwargs.py:112:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation callables_kwargs.py:123:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` 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` -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` -callables_kwargs.py:195:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +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` +callables_kwargs.py:185:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 500efa063..92f8aec34 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -5,9 +5,7 @@ Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_i """ conformance_automated = "Fail" errors_diff = """ -Line 176: Expected 1 errors -Line 194: Expected 1 errors -Line 193: Unexpected errors ['callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef]'] +Line 184: Expected 1 errors """ output = """ 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 callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] 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] -callables_kwargs.py:193: error: Name "func10" already defined on line 180 [no-redef] -callables_kwargs.py:195: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD6"; expected "str" [arg-type] +callables_kwargs.py:185: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD5"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index 22091a618..cc8b9df93 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -142,15 +142,11 @@ class TD3(TypedDict): name: str -class TD4(TypedDict, closed=False): +class TD4(TypedDict, closed=True): name: str -class TD5(TypedDict, closed=True): - name: str - - -class TD6(TypedDict, extra_items=int): +class TD5(TypedDict, extra_items=int): name: str @@ -163,9 +159,8 @@ def takes_name_kwargs(name: str, **kwargs) -> None: # > It is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` -# > to another function if that function has ``**kwargs`` in its signature as well. In this situation, -# > type checkers should error if the ``TypedDict`` is explicitly open (``closed=False``) or has ``extra_items``. -# > Additionally, type checkers may error if the ``TypedDict`` is implicitly open. +# > to another function if that function has ``**kwargs`` in its signature as well. Type checkers +# > should error if the ``TypedDict`` has ``extra_items``, and may error if the ``TypedDict`` is open. def func8(**kwargs: Unpack[TD3]) -> None: takes_name(**kwargs) # E?: a subtype may contain unknown keys @@ -173,11 +168,6 @@ def func8(**kwargs: Unpack[TD3]) -> None: def func9(**kwargs: Unpack[TD4]) -> None: - takes_name(**kwargs) # E: a subtype may contain unknown keys - takes_name_kwargs(**kwargs) - - -def func10(**kwargs: Unpack[TD5]) -> None: takes_name(**kwargs) takes_name_kwargs(**kwargs) @@ -190,7 +180,7 @@ def takes_name_int_kwargs(name: str, **kwargs: int) -> None: ... -def func10(**kwargs: Unpack[TD6]) -> None: +def func10(**kwargs: Unpack[TD5]) -> None: takes_name(**kwargs) # E: extra items may be present takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible takes_name_int_kwargs(**kwargs) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index bf4dc383e..b29e70292 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -413,10 +413,9 @@ it needs completely ignoring any additional values. The calls to ``bar`` and ``spam`` will fail because an unexpected keyword argument will be passed to the ``takes_name`` function. -Therefore, it is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` -to another function if that function has ``**kwargs`` in its signature as well. In this situation, -type checkers should error if the ``TypedDict`` is explicitly open (``closed=False``) or has ``extra_items``. -Additionally, type checkers may error if the ``TypedDict`` is implicitly open. +Therefore, it is only safe to pass ``kwargs`` hinted with an unpacked, non-:term:`closed` ``TypedDict`` +to another function if that function has ``**kwargs`` in its signature as well. Type checkers should +error if the ``TypedDict`` has :term:`extra items`, and may error if the ``TypedDict`` is :term:`open`. In cases similar to the ``bar`` function above the problem could be worked around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired From 4a3bbc69473e3d2a38b6640a708e48fb6fabda5d Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Thu, 13 Aug 2026 15:39:28 -0400 Subject: [PATCH 04/16] address reviewer comments, revise spec and add a bunch of test cases --- .../results/mypy/callables_kwargs.toml | 67 +++++++------ .../results/pycroscope/callables_kwargs.toml | 43 +++++---- .../results/pyrefly/callables_kwargs.toml | 47 +++++---- .../results/pyright/callables_kwargs.toml | 44 +++++---- conformance/results/results.html | 5 - conformance/results/ty/callables_kwargs.toml | 40 ++++---- .../results/zuban/callables_kwargs.toml | 55 ++++++----- conformance/tests/callables_kwargs.py | 95 +++++++++++++++---- docs/spec/callables.rst | 17 ++-- 9 files changed, 261 insertions(+), 152 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index eec7a9a13..764525eb9 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -2,38 +2,51 @@ conformant = "Partial" notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. Does not support the `closed` and `extra_items` TypedDict class arguments. -Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. """ output = """ -callables_kwargs.py:47: error: Missing named argument "v1" for "func1" [call-arg] -callables_kwargs.py:47: error: Missing named argument "v3" for "func1" [call-arg] -callables_kwargs.py:52: error: Unexpected keyword argument "v4" for "func1" [call-arg] -callables_kwargs.py:53: error: Too many positional arguments for "func1" [misc] -callables_kwargs.py:59: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] -callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "int" [arg-type] -callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "str" [arg-type] -callables_kwargs.py:64: error: "func1" gets multiple values for keyword argument "v1" [misc] -callables_kwargs.py:65: error: "func2" gets multiple values for keyword argument "v3" [misc] -callables_kwargs.py:65: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] -callables_kwargs.py:66: error: "func2" gets multiple values for keyword argument "v1" [misc] -callables_kwargs.py:102: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol3") [assignment] -callables_kwargs.py:102: note: "TDProtocol3.__call__" has type "def __call__(self, *, v1: int, v2: int, v3: str) -> None" -callables_kwargs.py:103: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol4") [assignment] -callables_kwargs.py:103: note: "TDProtocol4.__call__" has type "def __call__(self, *, v1: int) -> None" -callables_kwargs.py:104: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol5") [assignment] -callables_kwargs.py:104: note: "TDProtocol5.__call__" has type "def __call__(self, v1: int, v3: str) -> None" -callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] -callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] -callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:55: error: Missing named argument "v1" for "func1" [call-arg] +callables_kwargs.py:55: error: Missing named argument "v3" for "func1" [call-arg] +callables_kwargs.py:60: error: Unexpected keyword argument "v4" for "func1" [call-arg] +callables_kwargs.py:61: error: Too many positional arguments for "func1" [misc] +callables_kwargs.py:67: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] +callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "int" [arg-type] +callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "str" [arg-type] +callables_kwargs.py:72: error: "func1" gets multiple values for keyword argument "v1" [misc] +callables_kwargs.py:73: error: "func2" gets multiple values for keyword argument "v3" [misc] +callables_kwargs.py:73: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] +callables_kwargs.py:74: error: "func2" gets multiple values for keyword argument "v1" [misc] +callables_kwargs.py:121: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol3") [assignment] +callables_kwargs.py:121: note: "TDProtocol3.__call__" has type "def __call__(self, *, v1: int, v2: int, v3: str) -> None" +callables_kwargs.py:122: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol4") [assignment] +callables_kwargs.py:122: note: "TDProtocol4.__call__" has type "def __call__(self, *, v1: int) -> None" +callables_kwargs.py:123: error: Incompatible types in assignment (expression has type "def func1(**kwargs: **TD2) -> None", variable has type "TDProtocol5") [assignment] +callables_kwargs.py:123: note: "TDProtocol5.__call__" has type "def __call__(self, v1: int, v3: str) -> None" +callables_kwargs.py:131: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] +callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict [misc] +callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:170: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] """ conformance_automated = "Fail" errors_diff = """ -Line 135: Expected 1 errors -Line 184: Expected 1 errors -Line 185: Expected 1 errors -Line 145: Unexpected errors ['callables_kwargs.py:145: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 149: Unexpected errors ['callables_kwargs.py:149: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 154: Expected 1 errors +Line 206: Expected 1 errors +Line 209: Expected 1 errors +Line 215: Expected 1 errors +Line 218: Expected 1 errors +Line 231: Expected 1 errors +Line 232: Expected 1 errors +Line 234: Expected 1 errors +Line 235: Expected 1 errors +Line 23: Unexpected errors ['callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 27: Unexpected errors ['callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 166: Unexpected errors ['callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 170: Unexpected errors ['callables_kwargs.py:170: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 174: Unexpected errors ['callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 178: Unexpected errors ['callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] """ diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 710649de2..9e69aac7b 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -1,27 +1,36 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. """ conformance_automated = "Fail" errors_diff = """ -Line 184: Expected 1 errors -Line 185: Expected 1 errors +Line 206: Expected 1 errors +Line 209: Expected 1 errors +Line 215: Expected 1 errors +Line 218: Expected 1 errors +Line 231: Expected 1 errors +Line 232: Expected 1 errors +Line 234: Expected 1 errors +Line 235: Expected 1 errors +Line 155: Unexpected errors ["./callables_kwargs.py:155:0: Incompatible assignment: expected callables_kwargs.TDProtocol7, got function 'callables_kwargs.func7' [incompatible_assignment]"] +Line 156: Unexpected errors ["./callables_kwargs.py:156:0: Incompatible assignment: expected callables_kwargs.TDProtocol8, got function 'callables_kwargs.func7' [incompatible_assignment]"] """ output = """ -./callables_kwargs.py:47:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] -./callables_kwargs.py:52:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] -./callables_kwargs.py:53:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] -./callables_kwargs.py:59:4: Incompatible argument type for v1: expected int but got str [incompatible_argument] -./callables_kwargs.py:62:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] -./callables_kwargs.py:64:4: Multiple values provided for argument 'v1' [incompatible_call] -./callables_kwargs.py:65:4: In call to callables_kwargs.func2: Parameter 'v3' provided as both a positional and a keyword argument [incompatible_call] -./callables_kwargs.py:66:4: Multiple values provided for argument 'v1' [incompatible_call] -./callables_kwargs.py:102:0: Incompatible assignment: expected callables_kwargs.TDProtocol3, got function 'callables_kwargs.func1' [incompatible_assignment] -./callables_kwargs.py:103:0: Incompatible assignment: expected callables_kwargs.TDProtocol4, got function 'callables_kwargs.func1' [incompatible_assignment] -./callables_kwargs.py:104:0: Incompatible assignment: expected callables_kwargs.TDProtocol5, got function 'callables_kwargs.func1' [incompatible_assignment] -./callables_kwargs.py:112:21: Parameter v1 overlaps with TypedDict key in **kwargs [invalid_annotation] -./callables_kwargs.py:123:12: Expected TypedDict type inside Unpack[] for **kwargs [invalid_annotation] -./callables_kwargs.py:135:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] +./callables_kwargs.py:55:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] +./callables_kwargs.py:60:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] +./callables_kwargs.py:61:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] +./callables_kwargs.py:67:4: Incompatible argument type for v1: expected int but got str [incompatible_argument] +./callables_kwargs.py:70:4: In call to callables_kwargs.func1: Got an unexpected keyword argument 'v4' [incompatible_call] +./callables_kwargs.py:72:4: Multiple values provided for argument 'v1' [incompatible_call] +./callables_kwargs.py:73:4: In call to callables_kwargs.func2: Parameter 'v3' provided as both a positional and a keyword argument [incompatible_call] +./callables_kwargs.py:74:4: Multiple values provided for argument 'v1' [incompatible_call] +./callables_kwargs.py:121:0: Incompatible assignment: expected callables_kwargs.TDProtocol3, got function 'callables_kwargs.func1' [incompatible_assignment] +./callables_kwargs.py:122:0: Incompatible assignment: expected callables_kwargs.TDProtocol4, got function 'callables_kwargs.func1' [incompatible_assignment] +./callables_kwargs.py:123:0: Incompatible assignment: expected callables_kwargs.TDProtocol5, got function 'callables_kwargs.func1' [incompatible_assignment] +./callables_kwargs.py:131:21: Parameter v1 overlaps with TypedDict key in **kwargs [invalid_annotation] +./callables_kwargs.py:142:12: Expected TypedDict type inside Unpack[] for **kwargs [invalid_annotation] +./callables_kwargs.py:154:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] +./callables_kwargs.py:155:0: Incompatible assignment: expected callables_kwargs.TDProtocol7, got function 'callables_kwargs.func7' [incompatible_assignment] +./callables_kwargs.py:156:0: Incompatible assignment: expected callables_kwargs.TDProtocol8, got function 'callables_kwargs.func7' [incompatible_assignment] """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index 666a28973..b15c28537 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -1,30 +1,37 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. """ conformance_automated = "Fail" errors_diff = """ -Line 184: Expected 1 errors -Line 185: Expected 1 errors +Line 206: Expected 1 errors +Line 209: Expected 1 errors +Line 215: Expected 1 errors +Line 218: Expected 1 errors +Line 231: Expected 1 errors +Line 232: Expected 1 errors +Line 234: Expected 1 errors +Line 235: Expected 1 errors +Line 156: Unexpected errors ["`(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol8` [bad-assignment]"] """ output = """ -ERROR callables_kwargs.py:47:10-12: Missing argument `v1` in function `func1` [missing-argument] -ERROR callables_kwargs.py:47:10-12: Missing argument `v3` in function `func1` [missing-argument] -ERROR callables_kwargs.py:52:32-34: Unexpected keyword argument `v4` in function `func1` [unexpected-keyword] -ERROR callables_kwargs.py:53:11-12: Expected argument `v1` to be passed by name in function `func1` [unexpected-positional-argument] -ERROR callables_kwargs.py:53:11-12: Expected 0 positional arguments, got 3 in function `func1` [bad-argument-count] -ERROR callables_kwargs.py:53:14-16: Expected argument `v3` to be passed by name in function `func1` [unexpected-positional-argument] -ERROR callables_kwargs.py:59:11-20: Unpacked keyword argument `str` is not assignable to parameter `v1` with type `int` in function `func1` [bad-argument-type] -ERROR callables_kwargs.py:64:17-22: Multiple values for argument `v1` in function `func1` [bad-keyword-argument] -ERROR callables_kwargs.py:65:11-12: Argument `Literal[1]` is not assignable to parameter `v3` with type `str` in function `func2` [bad-argument-type] -ERROR callables_kwargs.py:65:14-19: Multiple values for argument `v3` in function `func2` [bad-keyword-argument] -ERROR callables_kwargs.py:66:17-22: Multiple values for argument `v1` in function `func2` [bad-keyword-argument] -ERROR callables_kwargs.py:102:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol3` [bad-assignment] -ERROR callables_kwargs.py:103:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol4` [bad-assignment] -ERROR callables_kwargs.py:104:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol5` [bad-assignment] -ERROR callables_kwargs.py:112:20-41: TypedDict key 'v1' in **kwargs overlaps with parameter 'v1' [bad-function-definition] -ERROR callables_kwargs.py:123:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] -ERROR callables_kwargs.py:135:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] +ERROR callables_kwargs.py:55:10-12: Missing argument `v1` in function `func1` [missing-argument] +ERROR callables_kwargs.py:55:10-12: Missing argument `v3` in function `func1` [missing-argument] +ERROR callables_kwargs.py:60:32-34: Unexpected keyword argument `v4` in function `func1` [unexpected-keyword] +ERROR callables_kwargs.py:61:11-12: Expected argument `v1` to be passed by name in function `func1` [unexpected-positional-argument] +ERROR callables_kwargs.py:61:11-12: Expected 0 positional arguments, got 3 in function `func1` [bad-argument-count] +ERROR callables_kwargs.py:61:14-16: Expected argument `v3` to be passed by name in function `func1` [unexpected-positional-argument] +ERROR callables_kwargs.py:67:11-20: Unpacked keyword argument `str` is not assignable to parameter `v1` with type `int` in function `func1` [bad-argument-type] +ERROR callables_kwargs.py:72:17-22: Multiple values for argument `v1` in function `func1` [bad-keyword-argument] +ERROR callables_kwargs.py:73:11-12: Argument `Literal[1]` is not assignable to parameter `v3` with type `str` in function `func2` [bad-argument-type] +ERROR callables_kwargs.py:73:14-19: Multiple values for argument `v3` in function `func2` [bad-keyword-argument] +ERROR callables_kwargs.py:74:17-22: Multiple values for argument `v1` in function `func2` [bad-keyword-argument] +ERROR callables_kwargs.py:121:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol3` [bad-assignment] +ERROR callables_kwargs.py:122:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol4` [bad-assignment] +ERROR callables_kwargs.py:123:19-24: `(**kwargs: Unpack[TD2]) -> None` is not assignable to `TDProtocol5` [bad-assignment] +ERROR callables_kwargs.py:131:20-41: TypedDict key 'v1' in **kwargs overlaps with parameter 'v1' [bad-function-definition] +ERROR callables_kwargs.py:142:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] +ERROR callables_kwargs.py:154:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] +ERROR callables_kwargs.py:156:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol8` [bad-assignment] """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 8173c49e4..c70be3c93 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -1,43 +1,53 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. """ output = """ -callables_kwargs.py:29:5 - error: Could not access item in TypedDict +callables_kwargs.py:37:5 - error: Could not access item in TypedDict   "v2" is not a required key in "TD2", so access may result in runtime exception (reportTypedDictNotRequiredAccess) -callables_kwargs.py:47:5 - error: Arguments missing for parameters "v1", "v3" (reportCallIssue) -callables_kwargs.py:52:32 - error: No parameter named "v4" (reportCallIssue) -callables_kwargs.py:53:11 - error: Expected 0 positional arguments (reportCallIssue) -callables_kwargs.py:59:13 - error: Argument of type "str" cannot be assigned to parameter "v1" of type "int" in function "func1" +callables_kwargs.py:55:5 - error: Arguments missing for parameters "v1", "v3" (reportCallIssue) +callables_kwargs.py:60:32 - error: No parameter named "v4" (reportCallIssue) +callables_kwargs.py:61:11 - error: Expected 0 positional arguments (reportCallIssue) +callables_kwargs.py:67:13 - error: Argument of type "str" cannot be assigned to parameter "v1" of type "int" in function "func1"   "str" is not assignable to "int" (reportArgumentType) -callables_kwargs.py:64:19 - error: Unable to match unpacked TypedDict argument to parameters +callables_kwargs.py:72:19 - error: Unable to match unpacked TypedDict argument to parameters   Parameter "v1" is already assigned (reportCallIssue) -callables_kwargs.py:65:16 - error: Unable to match unpacked TypedDict argument to parameters +callables_kwargs.py:73:16 - error: Unable to match unpacked TypedDict argument to parameters   Parameter "v3" is already assigned (reportCallIssue) -callables_kwargs.py:66:19 - error: Unable to match unpacked TypedDict argument to parameters +callables_kwargs.py:74:19 - error: Unable to match unpacked TypedDict argument to parameters   Parameter "v1" is already assigned (reportCallIssue) -callables_kwargs.py:102:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol3" +callables_kwargs.py:121:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol3"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(*, v1: int, v2: int, v3: str) -> None"     Keyword parameter "v2" of type "int" is incompatible with type "str"       "int" is not assignable to "str" (reportAssignmentType) -callables_kwargs.py:103:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol4" +callables_kwargs.py:122:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol4"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(*, v1: int) -> None"     Extra parameter "v3" (reportAssignmentType) -callables_kwargs.py:104:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol5" +callables_kwargs.py:123:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol5"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(v1: int, v3: str) -> None"     Function accepts too many positional parameters; expected 0 but received 2       Extra parameter "v1"       Extra parameter "v3" (reportAssignmentType) -callables_kwargs.py:112:30 - error: Typed dictionary overlaps with keyword parameter: v1 (reportGeneralTypeIssues) -callables_kwargs.py:123:21 - error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues) -callables_kwargs.py:135:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6" +callables_kwargs.py:131:30 - error: Typed dictionary overlaps with keyword parameter: v1 (reportGeneralTypeIssues) +callables_kwargs.py:142:21 - error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues) +callables_kwargs.py:154:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) -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" +callables_kwargs.py:206:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "object" is not assignable to "str" (reportArgumentType) +callables_kwargs.py:209:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "object" is not assignable to "str" (reportArgumentType) +callables_kwargs.py:215:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "object" is not assignable to "str" (reportArgumentType) +callables_kwargs.py:218:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "object" is not assignable to "str" (reportArgumentType) +callables_kwargs.py:232:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "int" is not assignable to "str" (reportArgumentType) +callables_kwargs.py:235:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 184: Expected 1 errors +Line 231: Expected 1 errors +Line 234: Expected 1 errors """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 39a0e2081..bd7aaa6c7 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1581,7 +1581,6 @@

      Python Type System Conformance Test Results

      • Allows callable without kwargs to be assigned to callable with unpacked kwargs.
      • Does not support the closed and extra_items TypedDict class arguments.
      • -
      • Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no **kwargs.
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • Does not check the extra_items type of unpacked kwargs against the target callable's **kwargs annotation.
      @@ -1589,7 +1588,6 @@

      Python Type System Conformance Test Results

      Partial
        -
      • Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no **kwargs.
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • Does not check the extra_items type of unpacked kwargs against the target callable's **kwargs annotation.
      @@ -1597,7 +1595,6 @@

      Python Type System Conformance Test Results

      Partial
        -
      • Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no **kwargs.
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • Does not check the extra_items type of unpacked kwargs against the target callable's **kwargs annotation.
      @@ -1605,7 +1602,6 @@

      Python Type System Conformance Test Results

      Partial
        -
      • Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no **kwargs.
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      @@ -1613,7 +1609,6 @@

      Python Type System Conformance Test Results

      Partial
        -
      • Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no **kwargs.
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 44aa885c3..1b4e29f0c 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -3,21 +3,27 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ -callables_kwargs.py:47:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` -callables_kwargs.py:53:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` -callables_kwargs.py:53:11: error[too-many-positional-arguments] Too many positional arguments to function `func1`: expected 0, got 3 -callables_kwargs.py:59:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `int`, found `str` -callables_kwargs.py:62:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `str`, found `int | str` -callables_kwargs.py:64:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func1` -callables_kwargs.py:65:11: error[invalid-argument-type] Argument to function `func2` is incorrect: Expected `str`, found `Literal[1]` -callables_kwargs.py:65:14: error[parameter-already-assigned] Multiple values provided for parameter `v3` of function `func2` -callables_kwargs.py:66:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func2` -callables_kwargs.py:102:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol3` -callables_kwargs.py:103:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol4` -callables_kwargs.py:104:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol5` -callables_kwargs.py:112:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation -callables_kwargs.py:123:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` -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` -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` -callables_kwargs.py:185:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:55:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` +callables_kwargs.py:61:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` +callables_kwargs.py:61:11: error[too-many-positional-arguments] Too many positional arguments to function `func1`: expected 0, got 3 +callables_kwargs.py:67:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `int`, found `str` +callables_kwargs.py:70:11: error[invalid-argument-type] Argument to function `func1` is incorrect: Expected `str`, found `int | str` +callables_kwargs.py:72:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func1` +callables_kwargs.py:73:11: error[invalid-argument-type] Argument to function `func2` is incorrect: Expected `str`, found `Literal[1]` +callables_kwargs.py:73:14: error[parameter-already-assigned] Multiple values provided for parameter `v3` of function `func2` +callables_kwargs.py:74:17: error[parameter-already-assigned] Multiple values provided for parameter `v1` of function `func2` +callables_kwargs.py:121:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol3` +callables_kwargs.py:122:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol4` +callables_kwargs.py:123:19: error[invalid-assignment] Object of type `def func1(*, v1: int, v2: str = ..., v3: str, **kwargs: object) -> None` is not assignable to `TDProtocol5` +callables_kwargs.py:131:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation +callables_kwargs.py:142:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` +callables_kwargs.py:154:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6` +callables_kwargs.py:206:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:209:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:215:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:218:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:231:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:232:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:234:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:235:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 92f8aec34..fa6c2fa25 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -1,32 +1,41 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a non-closed TypedDict to a callable that has no `**kwargs`. Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. """ conformance_automated = "Fail" errors_diff = """ -Line 184: Expected 1 errors +Line 206: Expected 1 errors +Line 209: Expected 1 errors +Line 215: Expected 1 errors +Line 218: Expected 1 errors +Line 231: Expected 1 errors +Line 234: Expected 1 errors +Line 155: Unexpected errors ['callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment]'] +Line 156: Unexpected errors ['callables_kwargs.py:156: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol8") [assignment]'] """ output = """ -callables_kwargs.py:47: error: Missing named argument "v1" for "func1" [call-arg] -callables_kwargs.py:47: error: Missing named argument "v3" for "func1" [call-arg] -callables_kwargs.py:52: error: Unexpected keyword argument "v4" for "func1" [call-arg] -callables_kwargs.py:53: error: Too many positional arguments for "func1" [call-arg] -callables_kwargs.py:53: error: Missing named argument "v1" for "func1" [call-arg] -callables_kwargs.py:53: error: Missing named argument "v3" for "func1" [call-arg] -callables_kwargs.py:59: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] -callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "int" [arg-type] -callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] -callables_kwargs.py:62: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] -callables_kwargs.py:64: error: "func1" gets multiple values for keyword argument "v1" [call-arg] -callables_kwargs.py:65: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] -callables_kwargs.py:65: error: "func2" gets multiple values for keyword argument "v3" [call-arg] -callables_kwargs.py:66: error: "func2" gets multiple values for keyword argument "v1" [call-arg] -callables_kwargs.py:102: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol3") [assignment] -callables_kwargs.py:103: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol4") [assignment] -callables_kwargs.py:104: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol5") [assignment] -callables_kwargs.py:112: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] -callables_kwargs.py:123: error: Unpack item in ** parameter must be a TypedDict [misc] -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] -callables_kwargs.py:185: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TD5"; expected "str" [arg-type] +callables_kwargs.py:55: error: Missing named argument "v1" for "func1" [call-arg] +callables_kwargs.py:55: error: Missing named argument "v3" for "func1" [call-arg] +callables_kwargs.py:60: error: Unexpected keyword argument "v4" for "func1" [call-arg] +callables_kwargs.py:61: error: Too many positional arguments for "func1" [call-arg] +callables_kwargs.py:61: error: Missing named argument "v1" for "func1" [call-arg] +callables_kwargs.py:61: error: Missing named argument "v3" for "func1" [call-arg] +callables_kwargs.py:67: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] +callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "int" [arg-type] +callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] +callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, int | str]"; expected "str" [arg-type] +callables_kwargs.py:72: error: "func1" gets multiple values for keyword argument "v1" [call-arg] +callables_kwargs.py:73: error: Argument 1 to "func2" has incompatible type "int"; expected "str" [arg-type] +callables_kwargs.py:73: error: "func2" gets multiple values for keyword argument "v3" [call-arg] +callables_kwargs.py:74: error: "func2" gets multiple values for keyword argument "v1" [call-arg] +callables_kwargs.py:121: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol3") [assignment] +callables_kwargs.py:122: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol4") [assignment] +callables_kwargs.py:123: error: Incompatible types in assignment (expression has type "def func1(**kwargs: Unpack[TD2]) -> None", variable has type "TDProtocol5") [assignment] +callables_kwargs.py:131: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] +callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict [misc] +callables_kwargs.py:154: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol6") [assignment] +callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment] +callables_kwargs.py:156: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol8") [assignment] +callables_kwargs.py:232: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:235: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index cc8b9df93..0d1367e0f 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -7,7 +7,7 @@ # This sample tests the handling of Unpack[TypedDict] when used with # a **kwargs parameter in a function signature. -from typing import Protocol, TypeVar, NotRequired, Required, Unpack, assert_type +from typing import Protocol, TypeVar, Never, NotRequired, Required, Unpack, assert_type from typing_extensions import TypedDict # for the `closed` and `extra_items` arguments @@ -20,6 +20,14 @@ class TD2(TD1): v3: Required[str] +class TD3(TD1, closed=True): + v3: Required[str] + + +class TD4(TD1, extra_items=Never): + v3: Required[str] + + def func1(**kwargs: Unpack[TD2]) -> None: v1 = kwargs["v1"] assert_type(v1, int) @@ -95,6 +103,17 @@ class TDProtocol6(Protocol): def __call__(self, **kwargs: Unpack[TD2]) -> None: ... + +class TDProtocol7(Protocol): + def __call__(self, **kwargs: Unpack[TD3]) -> None: + ... + + +class TDProtocol8(Protocol): + def __call__(self, **kwargs: Unpack[TD4]) -> None: + ... + + # Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#assignment v1: TDProtocol1 = func1 # OK @@ -124,7 +143,7 @@ def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a 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, +# > the source callable doesn’t contain **kwargs should be disallowed, if the TypedDict is :term:`closed`. 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 @@ -133,20 +152,30 @@ def func7(*, v1: int, v3: str, v2: str = "") -> None: v7: TDProtocol6 = func7 # E: source does not have kwargs +v8: TDProtocol7 = func7 # OK, unpacked TypedDict has closed=True +v9: TDProtocol8 = func7 # OK, unpacked TypedDict has extra_items=Never # Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#passing-kwargs-inside-a-function-to-another-function -class TD3(TypedDict): +class TDOpenImplicit(TypedDict): + name: str + + +class TDOpenExplicit(TypedDict, closed=False): name: str -class TD4(TypedDict, closed=True): +class TDClosed(TypedDict, closed=True): name: str -class TD5(TypedDict, extra_items=int): +class TDExtraItems(TypedDict, extra_items=int): + name: str + + +class TDExtraItemsNever(TypedDict, extra_items=Never): name: str @@ -158,29 +187,59 @@ def takes_name_kwargs(name: str, **kwargs) -> None: ... -# > It is only safe to pass ``kwargs`` hinted with an unpacked, non-closed ``TypedDict`` -# > to another function if that function has ``**kwargs`` in its signature as well. Type checkers -# > should error if the ``TypedDict`` has ``extra_items``, and may error if the ``TypedDict`` is open. +def takes_name_str_kwargs(name: str, **kwargs: str) -> None: + ... -def func8(**kwargs: Unpack[TD3]) -> None: - takes_name(**kwargs) # E?: a subtype may contain unknown keys - takes_name_kwargs(**kwargs) +def takes_name_int_kwargs(name: str, **kwargs: int) -> None: + ... -def func9(**kwargs: Unpack[TD4]) -> None: - takes_name(**kwargs) + +# > Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call +# > if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. +# > If the function being called has ``**kwargs``, checkers should error if the TypedDict's extra items are not assignable to the type of ``**kwargs``. +# > If the function being called does not have ``**kwargs``, checkers may error if the TypedDict is :term:`open`. + +def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> None: + takes_name(**value) # E?: a subtype may contain unknown keys + takes_name_kwargs(**value) + takes_name_str_kwargs(**value) # E: extra items type is not compatible + takes_name(**kwargs) # E?: a subtype may contain unknown keys takes_name_kwargs(**kwargs) + takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible -def takes_name_str_kwargs(name: str, **kwargs: str) -> None: - ... +def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> None: + takes_name(**value) # E?: a subtype may contain unknown keys + takes_name_kwargs(**value) + takes_name_str_kwargs(**value) # E: extra items type is not compatible + takes_name(**kwargs) # E?: a subtype may contain unknown keys + takes_name_kwargs(**kwargs) + takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible -def takes_name_int_kwargs(name: str, **kwargs: int) -> None: - ... +def kwargs_closed(value: TDClosed, **kwargs: Unpack[TDClosed]) -> None: + takes_name(**value) + takes_name_kwargs(**value) + takes_name_str_kwargs(**value) + takes_name(**kwargs) + takes_name_kwargs(**kwargs) + takes_name_str_kwargs(**kwargs) -def func10(**kwargs: Unpack[TD5]) -> None: +def kwargs_extra_items(value: TDExtraItems, **kwargs: Unpack[TDExtraItems]) -> None: + takes_name(**value) # E: extra items may be present + takes_name_str_kwargs(**value) # E: extra items type is not compatible + takes_name_int_kwargs(**value) takes_name(**kwargs) # E: extra items may be present takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible takes_name_int_kwargs(**kwargs) + + +def kwargs_extra_items_never(value: TDExtraItemsNever, **kwargs: Unpack[TDExtraItemsNever]) -> None: + takes_name(**value) + takes_name_kwargs(**value) + takes_name_str_kwargs(**value) + takes_name(**kwargs) + takes_name_kwargs(**kwargs) + takes_name_str_kwargs(**kwargs) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index b29e70292..edb39a861 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -304,9 +304,9 @@ only:: The reverse 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 +``**kwargs`` should be disallowed, if the TypedDict is :term:`closed`. 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 dest(**kwargs: Unpack[Animal]): ... @@ -366,8 +366,8 @@ traditionally typed ``**kwargs`` aren't checked for keyword names. To summarize, function parameters should behave contravariantly and function return types should behave covariantly. -Passing kwargs inside a function to another function -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Unpacking a TypedDict as keyword arguments +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :ref:`A previous point ` mentions the problem of possibly passing additional keyword arguments by @@ -413,9 +413,10 @@ it needs completely ignoring any additional values. The calls to ``bar`` and ``spam`` will fail because an unexpected keyword argument will be passed to the ``takes_name`` function. -Therefore, it is only safe to pass ``kwargs`` hinted with an unpacked, non-:term:`closed` ``TypedDict`` -to another function if that function has ``**kwargs`` in its signature as well. Type checkers should -error if the ``TypedDict`` has :term:`extra items`, and may error if the ``TypedDict`` is :term:`open`. +Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call +if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. +If the function being called has ``**kwargs``, checkers should error if the TypedDict's extra items are not assignable to the type of ``**kwargs``. +If the function being called does not have ``**kwargs``, checkers may error if the TypedDict is :term:`open`. In cases similar to the ``bar`` function above the problem could be worked around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired From b2453bb573ac35bf93db20c555e1641e8d4b185a Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Thu, 13 Aug 2026 15:43:19 -0400 Subject: [PATCH 05/16] modify notes --- .../results/mypy/callables_kwargs.toml | 4 ++-- .../results/pycroscope/callables_kwargs.toml | 5 +++-- .../results/pyrefly/callables_kwargs.toml | 5 +++-- .../results/pyright/callables_kwargs.toml | 2 +- conformance/results/results.html | 20 +++++++++++-------- .../results/zuban/callables_kwargs.toml | 4 +++- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 764525eb9..ea50dfab9 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -2,8 +2,8 @@ conformant = "Partial" notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. Does not support the `closed` and `extra_items` TypedDict class arguments. -Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. -Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. +Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. """ output = """ callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 9e69aac7b..2f40f5ee5 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -1,7 +1,8 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. -Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. +Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. """ conformance_automated = "Fail" errors_diff = """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index b15c28537..d90812c47 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -1,7 +1,8 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. -Does not check the `extra_items` type of unpacked kwargs against the target callable's `**kwargs` annotation. +Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a TypedDict that sets `extra_items=Never`. """ conformance_automated = "Fail" errors_diff = """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index c70be3c93..418dcd9f7 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -1,6 +1,6 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. """ output = """ callables_kwargs.py:37:5 - error: Could not access item in TypedDict diff --git a/conformance/results/results.html b/conformance/results/results.html index bd7aaa6c7..bd77af978 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1581,35 +1581,39 @@

      Python Type System Conformance Test Results

      • Allows callable without kwargs to be assigned to callable with unpacked kwargs.
      • Does not support the closed and extra_items TypedDict class arguments.
      • -
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • -
      • Does not check the extra_items type of unpacked kwargs against the target callable's **kwargs annotation.
      • +
      • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
      • +
      • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
      Partial
        -
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • -
      • Does not check the extra_items type of unpacked kwargs against the target callable's **kwargs annotation.
      • +
      • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
      • +
      • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
      • +
      • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
      Partial
        -
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • -
      • Does not check the extra_items type of unpacked kwargs against the target callable's **kwargs annotation.
      • +
      • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
      • +
      • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
      • +
      • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a TypedDict that sets extra_items=Never.
      Partial
        -
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • +
      • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
      Pass Partial
        -
      • Does not reject passing unpacked kwargs typed with a TypedDict that has extra_items to a callable that has no **kwargs.
      • +
      • Does not check the type of an open TypedDict's extra items against the target callable's **kwargs annotation.
      • +
      • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
      • +
      • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
      diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index fa6c2fa25..7a6e4c8c4 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -1,6 +1,8 @@ conformant = "Partial" notes = """ -Does not reject passing unpacked kwargs typed with a TypedDict that has `extra_items` to a callable that has no `**kwargs`. +Does not check the type of an open TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. """ conformance_automated = "Fail" errors_diff = """ From 722ec37d699aa5dc75b403818f07619ed6be975b Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Fri, 14 Aug 2026 23:07:27 -0400 Subject: [PATCH 06/16] add additional conformance test cases --- .../results/mypy/callables_kwargs.toml | 20 ++++++++----- .../results/pycroscope/callables_kwargs.toml | 20 ++++++++----- .../results/pyrefly/callables_kwargs.toml | 20 ++++++++----- .../results/pyright/callables_kwargs.toml | 22 +++++++++------ conformance/results/results.html | 8 ++++++ conformance/results/ty/callables_kwargs.toml | 18 +++++++----- .../results/zuban/callables_kwargs.toml | 18 +++++++----- conformance/tests/callables_kwargs.py | 28 +++++++++++++++---- docs/spec/callables.rst | 7 +++-- 9 files changed, 110 insertions(+), 51 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index ea50dfab9..4e084ba48 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -3,7 +3,9 @@ notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. Does not support the `closed` and `extra_items` TypedDict class arguments. Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ output = """ callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] @@ -35,14 +37,18 @@ callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "_ conformance_automated = "Fail" errors_diff = """ Line 154: Expected 1 errors -Line 206: Expected 1 errors -Line 209: Expected 1 errors +Line 212: Expected 1 errors Line 215: Expected 1 errors -Line 218: Expected 1 errors -Line 231: Expected 1 errors -Line 232: Expected 1 errors -Line 234: Expected 1 errors -Line 235: Expected 1 errors +Line 223: Expected 1 errors +Line 226: Expected 1 errors +Line 243: Expected 1 errors +Line 244: Expected 1 errors +Line 246: Expected 1 errors +Line 247: Expected 1 errors +Line 249: Expected 1 errors +Line 250: Expected 1 errors +Line 251: Expected 1 errors +Line 252: Expected 1 errors Line 23: Unexpected errors ['callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 27: Unexpected errors ['callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 166: Unexpected errors ['callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 2f40f5ee5..6cab48da8 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -1,19 +1,25 @@ conformant = "Partial" notes = """ Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. """ conformance_automated = "Fail" errors_diff = """ -Line 206: Expected 1 errors -Line 209: Expected 1 errors +Line 212: Expected 1 errors Line 215: Expected 1 errors -Line 218: Expected 1 errors -Line 231: Expected 1 errors -Line 232: Expected 1 errors -Line 234: Expected 1 errors -Line 235: Expected 1 errors +Line 223: Expected 1 errors +Line 226: Expected 1 errors +Line 243: Expected 1 errors +Line 244: Expected 1 errors +Line 246: Expected 1 errors +Line 247: Expected 1 errors +Line 249: Expected 1 errors +Line 250: Expected 1 errors +Line 251: Expected 1 errors +Line 252: Expected 1 errors Line 155: Unexpected errors ["./callables_kwargs.py:155:0: Incompatible assignment: expected callables_kwargs.TDProtocol7, got function 'callables_kwargs.func7' [incompatible_assignment]"] Line 156: Unexpected errors ["./callables_kwargs.py:156:0: Incompatible assignment: expected callables_kwargs.TDProtocol8, got function 'callables_kwargs.func7' [incompatible_assignment]"] """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index d90812c47..411d77975 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -1,19 +1,25 @@ conformant = "Partial" notes = """ Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. +Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a TypedDict that sets `extra_items=Never`. """ conformance_automated = "Fail" errors_diff = """ -Line 206: Expected 1 errors -Line 209: Expected 1 errors +Line 212: Expected 1 errors Line 215: Expected 1 errors -Line 218: Expected 1 errors -Line 231: Expected 1 errors -Line 232: Expected 1 errors -Line 234: Expected 1 errors -Line 235: Expected 1 errors +Line 223: Expected 1 errors +Line 226: Expected 1 errors +Line 243: Expected 1 errors +Line 244: Expected 1 errors +Line 246: Expected 1 errors +Line 247: Expected 1 errors +Line 249: Expected 1 errors +Line 250: Expected 1 errors +Line 251: Expected 1 errors +Line 252: Expected 1 errors Line 156: Unexpected errors ["`(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol8` [bad-assignment]"] """ output = """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 418dcd9f7..05e2036df 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -1,6 +1,8 @@ conformant = "Partial" notes = """ Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. +Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. """ output = """ callables_kwargs.py:37:5 - error: Could not access item in TypedDict @@ -33,21 +35,25 @@ callables_kwargs.py:142:21 - error: Expected TypedDict type argument for Unpack callables_kwargs.py:154:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) -callables_kwargs.py:206:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" -  "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:209:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:212:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) callables_kwargs.py:215:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:218:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:223:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +  "object" is not assignable to "str" (reportArgumentType) +callables_kwargs.py:226:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:232:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:244:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:235:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:247:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 231: Expected 1 errors -Line 234: Expected 1 errors +Line 243: Expected 1 errors +Line 246: Expected 1 errors +Line 249: Expected 1 errors +Line 250: Expected 1 errors +Line 251: Expected 1 errors +Line 252: Expected 1 errors """ diff --git a/conformance/results/results.html b/conformance/results/results.html index bd77af978..3714c2f5b 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1582,14 +1582,18 @@

      Python Type System Conformance Test Results

    • Allows callable without kwargs to be assigned to callable with unpacked kwargs.
    • Does not support the closed and extra_items TypedDict class arguments.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • +
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    Partial
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • +
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
    @@ -1597,7 +1601,9 @@

    Python Type System Conformance Test Results

    Partial
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • +
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a TypedDict that sets extra_items=Never.
    @@ -1605,6 +1611,8 @@

    Python Type System Conformance Test Results

    Partial
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • +
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    Pass diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 1b4e29f0c..3c8b8fd9c 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -18,12 +18,16 @@ callables_kwargs.py:123:19: error[invalid-assignment] Object of type `def func1( callables_kwargs.py:131:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation callables_kwargs.py:142:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` callables_kwargs.py:154:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6` -callables_kwargs.py:206:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:209:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:212:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` callables_kwargs.py:215:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:218:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:231:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:232:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:234:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:235:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:223:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:226:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:243:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:244:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:246:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:247:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:249:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:250:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:251:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:252:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 7a6e4c8c4..489511f47 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -6,12 +6,12 @@ Incorrectly rejects assigning a callable without `**kwargs` to a callable whose """ conformance_automated = "Fail" errors_diff = """ -Line 206: Expected 1 errors -Line 209: Expected 1 errors +Line 212: Expected 1 errors Line 215: Expected 1 errors -Line 218: Expected 1 errors -Line 231: Expected 1 errors -Line 234: Expected 1 errors +Line 223: Expected 1 errors +Line 226: Expected 1 errors +Line 243: Expected 1 errors +Line 246: Expected 1 errors Line 155: Unexpected errors ['callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment]'] Line 156: Unexpected errors ['callables_kwargs.py:156: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol8") [assignment]'] """ @@ -38,6 +38,10 @@ callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict callables_kwargs.py:154: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol6") [assignment] callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment] callables_kwargs.py:156: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol8") [assignment] -callables_kwargs.py:232: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:235: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:244: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:247: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:249: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:250: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:251: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:252: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index 0d1367e0f..e3b82ecc4 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -143,8 +143,8 @@ def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a TypedDict ... # > The situation where the destination callable contains **kwargs: Unpack[TypedDict] and -# > the source callable doesn’t contain **kwargs should be disallowed, if the TypedDict is :term:`closed`. This is because -# > we cannot be sure that additional keyword arguments are not being passed in when an instance of a subclass +# > the source callable doesn’t contain **kwargs should be disallowed, if the TypedDict is not :term:`closed`. +# > 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: @@ -156,7 +156,7 @@ def func7(*, v1: int, v3: str, v2: str = "") -> None: v9: TDProtocol8 = func7 # OK, unpacked TypedDict has extra_items=Never -# Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#passing-kwargs-inside-a-function-to-another-function +# Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#unpacking-a-typeddict-as-keyword-arguments class TDOpenImplicit(TypedDict): @@ -195,10 +195,16 @@ def takes_name_int_kwargs(name: str, **kwargs: int) -> None: ... +def takes_optional_label_int_kwargs(name: str, *, label: str = "", **kwargs: int) -> None: + ... + + +def takes_closed(**kwargs: Unpack[TDClosed]) -> None: + ... + + # > Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call # > if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. -# > If the function being called has ``**kwargs``, checkers should error if the TypedDict's extra items are not assignable to the type of ``**kwargs``. -# > If the function being called does not have ``**kwargs``, checkers may error if the TypedDict is :term:`open`. def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> None: takes_name(**value) # E?: a subtype may contain unknown keys @@ -207,6 +213,8 @@ def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> No takes_name(**kwargs) # E?: a subtype may contain unknown keys takes_name_kwargs(**kwargs) takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible + takes_closed(**value) # E?: a subtype may contain unknown keys + takes_closed(**kwargs) # E?: a subtype may contain unknown keys def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> None: @@ -216,6 +224,8 @@ def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> Non takes_name(**kwargs) # E?: a subtype may contain unknown keys takes_name_kwargs(**kwargs) takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible + takes_closed(**value) # E?: a subtype may contain unknown keys + takes_closed(**kwargs) # E?: a subtype may contain unknown keys def kwargs_closed(value: TDClosed, **kwargs: Unpack[TDClosed]) -> None: @@ -225,6 +235,8 @@ def kwargs_closed(value: TDClosed, **kwargs: Unpack[TDClosed]) -> None: takes_name(**kwargs) takes_name_kwargs(**kwargs) takes_name_str_kwargs(**kwargs) + takes_closed(**value) + takes_closed(**kwargs) def kwargs_extra_items(value: TDExtraItems, **kwargs: Unpack[TDExtraItems]) -> None: @@ -234,6 +246,10 @@ def kwargs_extra_items(value: TDExtraItems, **kwargs: Unpack[TDExtraItems]) -> N takes_name(**kwargs) # E: extra items may be present takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible takes_name_int_kwargs(**kwargs) + takes_closed(**value) # E: extra items may be present + takes_closed(**kwargs) # E: extra items may be present + takes_optional_label_int_kwargs(**value) # E: extra items type is not compatible w/ `label` param + takes_optional_label_int_kwargs(**kwargs) # E: extra items type is not compatible w/ `label` param def kwargs_extra_items_never(value: TDExtraItemsNever, **kwargs: Unpack[TDExtraItemsNever]) -> None: @@ -243,3 +259,5 @@ def kwargs_extra_items_never(value: TDExtraItemsNever, **kwargs: Unpack[TDExtraI takes_name(**kwargs) takes_name_kwargs(**kwargs) takes_name_str_kwargs(**kwargs) + takes_closed(**value) + takes_closed(**kwargs) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index edb39a861..93065de02 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -304,7 +304,7 @@ only:: The reverse situation where the destination callable contains ``**kwargs: Unpack[TypedDict]`` and the source callable doesn't contain -``**kwargs`` should be disallowed, if the TypedDict is :term:`closed`. This is because +``**kwargs`` should be disallowed, if the TypedDict is not :term:`closed`. 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:: @@ -415,8 +415,9 @@ argument will be passed to the ``takes_name`` function. Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. -If the function being called has ``**kwargs``, checkers should error if the TypedDict's extra items are not assignable to the type of ``**kwargs``. -If the function being called does not have ``**kwargs``, checkers may error if the TypedDict is :term:`open`. + +- If the function being called has ``**kwargs``, checkers should error if the TypedDict's :term:`extra items` are not assignable to the type of ``**kwargs``. For this rule, :term:`open` TypedDicts are treated as having extra items of type ``object``. +- If the function being called does not have ``**kwargs``, checkers may error if the TypedDict is :term:`open`, and should error if the TypedDict declares non-``Never`` :term:`extra items`. In cases similar to the ``bar`` function above the problem could be worked around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired From cdb84260358a6f89b66fa1f28bbb177ccb2caef0 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Thu, 27 Aug 2026 23:22:33 -0400 Subject: [PATCH 07/16] change wording from may -> should, make error required --- .../results/mypy/callables_kwargs.toml | 8 ++++++++ .../results/pycroscope/callables_kwargs.toml | 8 ++++++++ .../results/pyrefly/callables_kwargs.toml | 8 ++++++++ .../results/pyright/callables_kwargs.toml | 8 ++++++++ conformance/results/ty/callables_kwargs.toml | 10 +++++++++- .../results/zuban/callables_kwargs.toml | 8 ++++++++ conformance/tests/callables_kwargs.py | 20 +++++++++---------- docs/spec/callables.rst | 2 +- 8 files changed, 60 insertions(+), 12 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 4e084ba48..0b75bdb6c 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -37,10 +37,18 @@ callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "_ conformance_automated = "Fail" errors_diff = """ Line 154: Expected 1 errors +Line 210: Expected 1 errors Line 212: Expected 1 errors +Line 213: Expected 1 errors Line 215: Expected 1 errors +Line 216: Expected 1 errors +Line 217: Expected 1 errors +Line 221: Expected 1 errors Line 223: Expected 1 errors +Line 224: Expected 1 errors Line 226: Expected 1 errors +Line 227: Expected 1 errors +Line 228: Expected 1 errors Line 243: Expected 1 errors Line 244: Expected 1 errors Line 246: Expected 1 errors diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 6cab48da8..d2daffedc 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -8,10 +8,18 @@ Incorrectly rejects assigning a callable without `**kwargs` to a callable whose """ conformance_automated = "Fail" errors_diff = """ +Line 210: Expected 1 errors Line 212: Expected 1 errors +Line 213: Expected 1 errors Line 215: Expected 1 errors +Line 216: Expected 1 errors +Line 217: Expected 1 errors +Line 221: Expected 1 errors Line 223: Expected 1 errors +Line 224: Expected 1 errors Line 226: Expected 1 errors +Line 227: Expected 1 errors +Line 228: Expected 1 errors Line 243: Expected 1 errors Line 244: Expected 1 errors Line 246: Expected 1 errors diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index 411d77975..2850cd483 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -8,10 +8,18 @@ Incorrectly rejects assigning a callable without `**kwargs` to a callable whose """ conformance_automated = "Fail" errors_diff = """ +Line 210: Expected 1 errors Line 212: Expected 1 errors +Line 213: Expected 1 errors Line 215: Expected 1 errors +Line 216: Expected 1 errors +Line 217: Expected 1 errors +Line 221: Expected 1 errors Line 223: Expected 1 errors +Line 224: Expected 1 errors Line 226: Expected 1 errors +Line 227: Expected 1 errors +Line 228: Expected 1 errors Line 243: Expected 1 errors Line 244: Expected 1 errors Line 246: Expected 1 errors diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 05e2036df..23e0066f8 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -50,6 +50,14 @@ callables_kwargs.py:247:29 - error: Argument of type "int" cannot be assigned to """ conformance_automated = "Fail" errors_diff = """ +Line 210: Expected 1 errors +Line 213: Expected 1 errors +Line 216: Expected 1 errors +Line 217: Expected 1 errors +Line 221: Expected 1 errors +Line 224: Expected 1 errors +Line 227: Expected 1 errors +Line 228: Expected 1 errors Line 243: Expected 1 errors Line 246: Expected 1 errors Line 249: Expected 1 errors diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 3c8b8fd9c..d734fa02f 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -1,6 +1,14 @@ conformant = "Pass" -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 210: Expected 1 errors +Line 213: Expected 1 errors +Line 216: Expected 1 errors +Line 217: Expected 1 errors +Line 221: Expected 1 errors +Line 224: Expected 1 errors +Line 227: Expected 1 errors +Line 228: Expected 1 errors """ output = """ callables_kwargs.py:55:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 489511f47..b16a4bcae 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -6,10 +6,18 @@ Incorrectly rejects assigning a callable without `**kwargs` to a callable whose """ conformance_automated = "Fail" errors_diff = """ +Line 210: Expected 1 errors Line 212: Expected 1 errors +Line 213: Expected 1 errors Line 215: Expected 1 errors +Line 216: Expected 1 errors +Line 217: Expected 1 errors +Line 221: Expected 1 errors Line 223: Expected 1 errors +Line 224: Expected 1 errors Line 226: Expected 1 errors +Line 227: Expected 1 errors +Line 228: Expected 1 errors Line 243: Expected 1 errors Line 246: Expected 1 errors Line 155: Unexpected errors ['callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment]'] diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index e3b82ecc4..df1b3b638 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -203,29 +203,29 @@ def takes_closed(**kwargs: Unpack[TDClosed]) -> None: ... -# > Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call -# > if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. +# > It is only safe to unpack a non-:term:`closed` TypedDict in a function call if that function has +# > ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> None: - takes_name(**value) # E?: a subtype may contain unknown keys + takes_name(**value) # E: a subtype may contain unknown keys takes_name_kwargs(**value) takes_name_str_kwargs(**value) # E: extra items type is not compatible - takes_name(**kwargs) # E?: a subtype may contain unknown keys + takes_name(**kwargs) # E: a subtype may contain unknown keys takes_name_kwargs(**kwargs) takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible - takes_closed(**value) # E?: a subtype may contain unknown keys - takes_closed(**kwargs) # E?: a subtype may contain unknown keys + takes_closed(**value) # E: a subtype may contain unknown keys + takes_closed(**kwargs) # E: a subtype may contain unknown keys def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> None: - takes_name(**value) # E?: a subtype may contain unknown keys + takes_name(**value) # E: a subtype may contain unknown keys takes_name_kwargs(**value) takes_name_str_kwargs(**value) # E: extra items type is not compatible - takes_name(**kwargs) # E?: a subtype may contain unknown keys + takes_name(**kwargs) # E: a subtype may contain unknown keys takes_name_kwargs(**kwargs) takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible - takes_closed(**value) # E?: a subtype may contain unknown keys - takes_closed(**kwargs) # E?: a subtype may contain unknown keys + takes_closed(**value) # E: a subtype may contain unknown keys + takes_closed(**kwargs) # E: a subtype may contain unknown keys def kwargs_closed(value: TDClosed, **kwargs: Unpack[TDClosed]) -> None: diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index 93065de02..93a563b0a 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -417,7 +417,7 @@ Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a functio if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. - If the function being called has ``**kwargs``, checkers should error if the TypedDict's :term:`extra items` are not assignable to the type of ``**kwargs``. For this rule, :term:`open` TypedDicts are treated as having extra items of type ``object``. -- If the function being called does not have ``**kwargs``, checkers may error if the TypedDict is :term:`open`, and should error if the TypedDict declares non-``Never`` :term:`extra items`. +- If the function being called does not have ``**kwargs``, checkers should error if the TypedDict is :term:`open`, and should error if the TypedDict declares non-``Never`` :term:`extra items`. In cases similar to the ``bar`` function above the problem could be worked around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired From 5a1ff15eaa016819f13b271575866a630394c605 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Thu, 27 Aug 2026 23:36:21 -0400 Subject: [PATCH 08/16] update notes --- .../results/mypy/callables_kwargs.toml | 1 + .../results/pycroscope/callables_kwargs.toml | 1 + .../results/pyrefly/callables_kwargs.toml | 1 + .../results/pyright/callables_kwargs.toml | 1 + conformance/results/results.html | 249 +++++------------- conformance/results/ty/callables_kwargs.toml | 5 +- .../results/zuban/callables_kwargs.toml | 1 + 7 files changed, 76 insertions(+), 183 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 0b75bdb6c..f7f734a20 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -2,6 +2,7 @@ conformant = "Partial" notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. Does not support the `closed` and `extra_items` TypedDict class arguments. +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index d2daffedc..15c5be030 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -3,6 +3,7 @@ notes = """ Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index 2850cd483..a70182d8d 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -3,6 +3,7 @@ notes = """ Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a TypedDict that sets `extra_items=Never`. """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 23e0066f8..61d3dacb6 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -1,5 +1,6 @@ conformant = "Partial" notes = """ +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. diff --git a/conformance/results/results.html b/conformance/results/results.html index 3714c2f5b..57ab23b5e 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -265,11 +265,11 @@

    Python Type System Conformance Test Results

    mypy 2.1.0 - pycroscope 0.4.0 + pycroscope 0.5.0 pyrefly 1.3.0-dev.1 pyright 1.1.410 - ty 0.0.70 - zuban 0.8.2 + ty 0.0.75 + zuban 0.9.2 @@ -554,12 +554,7 @@

    Python Type System Conformance Test Results

  • Does not fully support defaults on TypeVarTuple and ParamSpec.
  • - - Partial -
      -
    • Numerous issues; does not support TypeVarTuple and ParamSpec defaults.
    • -
    - + Pass Pass Pass @@ -580,12 +575,7 @@

    Python Type System Conformance Test Results

  • Does not correctly handle defaults referencing other TypeVars.
  • - - Partial -
      -
    • Fails to apply default specializations in some cases.
    • -
    - + Pass Pass Pass Pass @@ -613,16 +603,11 @@

    Python Type System Conformance Test Results

    generics_mixed_variance_inference Pass - Unsupported + Pass Unsupported Unsupported Pass - - Partial -
      -
    • Does not infer covariance for a TypeVarTuple in a class with mixed type parameters.
    • -
    - + Pass generics_paramspec_basic @@ -668,7 +653,7 @@

    Python Type System Conformance Test Results

    generics_paramspec_variance Unsupported - Unsupported + Pass Unsupported Unsupported @@ -677,7 +662,7 @@

    Python Type System Conformance Test Results

  • Does not error when a ParamSpec is used in a position that violates its explicit variance.
  • - Unsupported + Pass generics_scoping @@ -792,12 +777,7 @@

    Python Type System Conformance Test Results

  • Does not following runtime scoping rules for type parameters in all cases.
  • - - Partial -
      -
    • Misses some details of scoping rules.
    • -
    - + Pass Pass Pass Pass @@ -809,7 +789,6 @@

    Python Type System Conformance Test Results

    Partial
    • Infers Node[Never] instead of Node[Any] when argument is not provided.
    • -
    • False negative on instance attribute access on type(node).
    Pass @@ -839,12 +818,7 @@

    Python Type System Conformance Test Results

  • Does not correctly solve TypeVarTuple with heterogeneous bounds.
  • - - Partial -
      -
    • Only partially supports TypeVarTuple in *args annotations.
    • -
    - + Pass Pass @@ -855,12 +829,7 @@

    Python Type System Conformance Test Results

  • Does not enforce that tuples captured by TypeVarTuple are same length.
  • - - Partial -
      -
    • Doesn't error when multiple type variable tuples appear in a PEP 695 type parameter list; only detects the Generic[...] form.
    • -
    - + Pass Pass Partial @@ -877,12 +846,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not correctly infer a TypeVarTuple that appears between fixed leading and trailing parameters in *args.
    • -
    - + Pass Pass @@ -930,7 +894,7 @@

    Python Type System Conformance Test Results

    generics_typevartuple_variance Unsupported - Unsupported + Pass Unsupported Unsupported @@ -939,7 +903,7 @@

    Python Type System Conformance Test Results

  • Does not error when a TypeVarTuple is used in a position that violates its explicit variance.
  • - Unsupported + Pass generics_upper_bound @@ -983,23 +947,16 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • polymorphic functions with bound self type influence variance inference,
    • -
    • which is not part of the variance inference algorithm as described in the spec.
    • -
    • See gh-2281 for details.
    • -
    - + Pass 23.5 / 33 • 71.2% - 28 / 33 • 84.8% + 33 / 33 • 100.0% 30 / 33 • 90.9% 28.5 / 33 • 86.4% - 29 / 33 • 87.9% 30 / 33 • 90.9% + 33 / 33 • 100.0% @@ -1085,12 +1042,7 @@

    Python Type System Conformance Test Results

  • Does not reject use of ClassVar in TypeAlias definition.
  • - - Partial -
      -
    • Does not reject use of ClassVar as a qualifier for a NamedTuple field.
    • -
    - + Pass Pass Pass Pass @@ -1105,13 +1057,7 @@

    Python Type System Conformance Test Results

  • the incompatible constructor overrides in ChildC2 are not flagged.
  • - - Partial -
      -
    • Does not honor @override compatibility checks for __init__ and __new__:
    • -
    • the incompatible constructor overrides in ChildC2 are not flagged.
    • -
    - + Pass Pass Partial @@ -1127,22 +1073,16 @@

    Python Type System Conformance Test Results

  • the incompatible constructor overrides in ChildC2 are not flagged.
  • - - Partial -
      -
    • Does not honor @override compatibility checks for __init__ and __new__:
    • -
    • the incompatible constructor overrides in ChildC2 are not flagged.
    • -
    - + Pass 1 / 2 • 50.0% - 1 / 2 • 50.0% + 2 / 2 • 100.0% 2 / 2 • 100.0% 1.5 / 2 • 75.0% 1.5 / 2 • 75.0% - 1.5 / 2 • 75.0% + 2 / 2 • 100.0% @@ -1221,6 +1161,7 @@

    Python Type System Conformance Test Results

    Partial
    • Fails to reject various weird annotations.
    • +
    • Rejects a valid recursive generic type alias.
    Pass @@ -1242,12 +1183,7 @@

    Python Type System Conformance Test Results

  • Incorrectly rejects the use of a class-scoped TypeVar in a TypeAliasType definition.
  • - - Partial -
      -
    • Rejects valid ParamSpec specialization.
    • -
    - + Pass Pass Pass @@ -1270,7 +1206,7 @@

    Python Type System Conformance Test Results

    5.5 / 7 • 78.6% - 5.5 / 7 • 78.6% + 6 / 7 • 85.7% 7 / 7 • 100.0% 7 / 7 • 100.0% 4 / 7 • 57.1% @@ -1384,12 +1320,7 @@

    Python Type System Conformance Test Results

  • Does not detect protocol mismatch if concrete method's parameters are position-only.
  • - - Partial -
      -
    • Incorrectly accepts an instance-only attribute as satisfying a ClassVar protocol member.
    • -
    - + Pass Pass Pass Pass @@ -1421,7 +1352,6 @@

    Python Type System Conformance Test Results

    Partial
      -
    • Fails to reject duplicate generic/protocol bases.
    • Treats global object as a literal.
    @@ -1530,22 +1460,17 @@

    Python Type System Conformance Test Results

  • Doesn't support variance keyword arguments to ParamSpec.
  • - Unsupported - - Partial -
      -
    • False report of ParamSpec variance keywords.
    • -
    - + Pass + Pass 9.5 / 11 • 86.4% - 9.5 / 11 • 86.4% - 10.5 / 11 • 95.5% + 10 / 11 • 90.9% 10.5 / 11 • 95.5% - 6.5 / 11 • 59.1% 10.5 / 11 • 95.5% + 7.5 / 11 • 68.2% + 11 / 11 • 100.0% @@ -1563,12 +1488,7 @@

    Python Type System Conformance Test Results

  • Does not treat *args: Any, **kargs: Any as ... when separated by keyword parameter.
  • - - Partial -
      -
    • Does not support callback protocols with PEP 695 ParamSpec type parameters.
    • -
    - + Pass Pass Pass Pass @@ -1581,6 +1501,7 @@

    Python Type System Conformance Test Results

    • Allows callable without kwargs to be assigned to callable with unpacked kwargs.
    • Does not support the closed and extra_items TypedDict class arguments.
    • +
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • @@ -1593,6 +1514,7 @@

      Python Type System Conformance Test Results

    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
    @@ -1603,6 +1525,7 @@

    Python Type System Conformance Test Results

  • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
  • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
  • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
  • +
  • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
  • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
  • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a TypedDict that sets extra_items=Never.
  • @@ -1610,15 +1533,22 @@

    Python Type System Conformance Test Results

    Partial
      +
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    - Pass Partial
      +
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • +
    + + + Partial +
      +
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • Does not check the type of an open TypedDict's extra items against the target callable's **kwargs annotation.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
    • @@ -1628,12 +1558,7 @@

      Python Type System Conformance Test Results

      callables_protocol Pass - - Partial -
        -
      • Does not support callback protocols with PEP 695 ParamSpec type parameters.
      • -
      - + Pass Pass Pass Pass @@ -1642,12 +1567,7 @@

      Python Type System Conformance Test Results

      callables_subtyping Pass - - Partial -
        -
      • Does not support callback protocols with PEP 695 ParamSpec type parameters.
      • -
      - + Pass Pass Pass Pass @@ -1656,10 +1576,10 @@

      Python Type System Conformance Test Results

      3 / 4 • 75.0% - 2 / 4 • 50.0% 3.5 / 4 • 87.5% 3.5 / 4 • 87.5% - 4 / 4 • 100.0% + 3.5 / 4 • 87.5% + 3.5 / 4 • 87.5% 3.5 / 4 • 87.5% @@ -1889,7 +1809,7 @@

      Python Type System Conformance Test Results

      Pass Pass Pass - Unsupported + Pass Pass @@ -1898,7 +1818,7 @@

      Python Type System Conformance Test Results

      1 / 1 • 100.0% 1 / 1 • 100.0% 1 / 1 • 100.0% - 0 / 1 • 0.0% + 1 / 1 • 100.0% 1 / 1 • 100.0% @@ -2035,12 +1955,7 @@

      Python Type System Conformance Test Results

      Pass Pass Pass - - Partial -
        -
      • Synthesizes a __slots__ attribute but does not validate attribute assignments against __slots__.
      • -
      - + Pass Pass @@ -2124,7 +2039,7 @@

      Python Type System Conformance Test Results

      15.5 / 16 • 96.9% 15.5 / 16 • 96.9% 16 / 16 • 100.0% - 15 / 16 • 93.8% + 15.5 / 16 • 96.9% 16 / 16 • 100.0% @@ -2273,12 +2188,7 @@

      Python Type System Conformance Test Results

      typeddicts_type_consistency Pass - - Partial -
        -
      • Considers TypedDicts to be assignable to plain dict types.
      • -
      - + Pass Pass Pass Pass @@ -2296,7 +2206,7 @@

      Python Type System Conformance Test Results

      11.5 / 14 • 82.1% - 13.5 / 14 • 96.4% + 14 / 14 • 100.0% 14 / 14 • 100.0% 13.5 / 14 • 96.4% 14 / 14 • 100.0% @@ -2372,12 +2282,7 @@

      Python Type System Conformance Test Results

    • Does not support version-conditional fields.
    - - Partial -
      -
    • Does not support precise type inference for slices over namedtuples.
    • -
    - + Pass Pass Pass Pass @@ -2418,7 +2323,7 @@

    Python Type System Conformance Test Results

    3 / 4 • 75.0% - 3.5 / 4 • 87.5% + 4 / 4 • 100.0% 4 / 4 • 100.0% 4 / 4 • 100.0% 4 / 4 • 100.0% @@ -2443,12 +2348,7 @@

    Python Type System Conformance Test Results

    enums_definition Pass - - Partial -
      -
    • Does not allow enum members to be conditional on version/platform checks.
    • -
    - + Pass Pass Pass Pass @@ -2471,12 +2371,7 @@

    Python Type System Conformance Test Results

    Pass - - Partial -
      -
    • Does not treat a complete union of all literal members as equivalent to the enum type.
    • -
    - + Pass enums_member_names @@ -2534,11 +2429,11 @@

    Python Type System Conformance Test Results

    4.5 / 6 • 75.0% - 5.5 / 6 • 91.7% 6 / 6 • 100.0% - 5.5 / 6 • 91.7% 6 / 6 • 100.0% 5.5 / 6 • 91.7% + 6 / 6 • 100.0% + 6 / 6 • 100.0% @@ -2562,12 +2457,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not fully simplify the negative branch of TypeIs narrowing for a union of fixed-length tuple types.
    • -
    - + Pass Pass @@ -2576,7 +2466,7 @@

    Python Type System Conformance Test Results

    2 / 2 • 100.0% 2 / 2 • 100.0% 2 / 2 • 100.0% - 1.5 / 2 • 75.0% + 2 / 2 • 100.0% 2 / 2 • 100.0% @@ -2623,12 +2513,7 @@

    Python Type System Conformance Test Results

    directives_disjoint_base Pass - - Partial -
      -
    • Does not reject invalid class definitions due to disjoint bases, but uses disjoint base information in type narrowing.
    • -
    - + Pass Pass Unsupported @@ -2727,7 +2612,7 @@

    Python Type System Conformance Test Results

    10 / 11 • 90.9% - 10.5 / 11 • 95.5% + 11 / 11 • 100.0% 11 / 11 • 100.0% 10 / 11 • 90.9% 10.5 / 11 • 95.5% @@ -2770,11 +2655,11 @@

    Python Type System Conformance Test Results

    108.5 / 145 • 74.8% - 127 / 145 • 87.6% + 137.5 / 145 • 94.8% 140 / 145 • 96.6% 135 / 145 • 93.1% - 128 / 145 • 88.3% - 139.5 / 145 • 96.2% + 131.5 / 145 • 90.7% + 144 / 145 • 99.3% diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index d734fa02f..2635de4d5 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -1,5 +1,8 @@ -conformant = "Pass" +conformant = "Partial" conformance_automated = "Fail" +notes = """ +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. +""" errors_diff = """ Line 210: Expected 1 errors Line 213: Expected 1 errors diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index b16a4bcae..37c933ff4 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -1,5 +1,6 @@ conformant = "Partial" notes = """ +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not check the type of an open TypedDict's extra items against the target callable's `**kwargs` annotation. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. From 20210735d58744376fde43db974efa530a5937a1 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Fri, 28 Aug 2026 22:44:19 -0400 Subject: [PATCH 09/16] update message --- conformance/results/mypy/callables_kwargs.toml | 1 + .../results/pycroscope/callables_kwargs.toml | 6 +----- .../results/pyrefly/callables_kwargs.toml | 3 ++- .../results/pyright/callables_kwargs.toml | 1 + conformance/results/results.html | 16 +++++++--------- conformance/results/ty/callables_kwargs.toml | 1 + conformance/results/zuban/callables_kwargs.toml | 4 +--- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index f7f734a20..a73684acf 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -3,6 +3,7 @@ notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. Does not support the `closed` and `extra_items` TypedDict class arguments. Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 15c5be030..fc5b69c33 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -1,11 +1,7 @@ conformant = "Partial" notes = """ -Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. -Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. -Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. -Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. -Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ conformance_automated = "Fail" errors_diff = """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index a70182d8d..baef65d46 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -1,9 +1,10 @@ conformant = "Partial" notes = """ +Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. -Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a TypedDict that sets `extra_items=Never`. """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 61d3dacb6..e677b7a26 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -1,6 +1,7 @@ conformant = "Partial" notes = """ Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. diff --git a/conformance/results/results.html b/conformance/results/results.html index 57ab23b5e..c9ac5f826 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1502,6 +1502,7 @@

    Python Type System Conformance Test Results

  • Allows callable without kwargs to be assigned to callable with unpacked kwargs.
  • Does not support the closed and extra_items TypedDict class arguments.
  • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
  • +
  • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
  • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
  • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
  • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
  • @@ -1511,21 +1512,18 @@

    Python Type System Conformance Test Results

    Partial
      -
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • -
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • -
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • -
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • -
    • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
    • +
    • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
    Partial
      +
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • -
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a TypedDict that sets extra_items=Never.
    @@ -1534,6 +1532,7 @@

    Python Type System Conformance Test Results

    Partial
    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • +
    • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • @@ -1543,15 +1542,14 @@

      Python Type System Conformance Test Results

      Partial
      • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
      • +
      • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
      Partial
      • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
      • -
      • Does not check the type of an open TypedDict's extra items against the target callable's **kwargs annotation.
      • -
      • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
      • -
      • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a closed TypedDict or one that sets extra_items=Never.
      • +
      • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
      diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 2635de4d5..66153ff91 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -2,6 +2,7 @@ conformant = "Partial" conformance_automated = "Fail" notes = """ Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ errors_diff = """ Line 210: Expected 1 errors diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 37c933ff4..0b4f236a7 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -1,9 +1,7 @@ conformant = "Partial" notes = """ Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. -Does not check the type of an open TypedDict's extra items against the target callable's `**kwargs` annotation. -Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. -Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a closed TypedDict or one that sets `extra_items=Never`. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ conformance_automated = "Fail" errors_diff = """ From 3b7c92613506f226085ec8c80079b0529aef4dc6 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Fri, 28 Aug 2026 23:03:44 -0400 Subject: [PATCH 10/16] add new test cases --- .../results/mypy/callables_kwargs.toml | 32 ++++++++------- .../results/pycroscope/callables_kwargs.toml | 38 ++++++++---------- .../results/pyrefly/callables_kwargs.toml | 30 +++++++------- .../results/pyright/callables_kwargs.toml | 40 +++++++++---------- conformance/results/ty/callables_kwargs.toml | 40 +++++++++---------- .../results/zuban/callables_kwargs.toml | 40 +++++++++---------- conformance/tests/callables_kwargs.py | 23 +++++++++++ 7 files changed, 130 insertions(+), 113 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index a73684acf..41996bd9d 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -35,34 +35,36 @@ callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init callables_kwargs.py:170: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:182: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] """ conformance_automated = "Fail" errors_diff = """ Line 154: Expected 1 errors -Line 210: Expected 1 errors -Line 212: Expected 1 errors -Line 213: Expected 1 errors -Line 215: Expected 1 errors -Line 216: Expected 1 errors -Line 217: Expected 1 errors -Line 221: Expected 1 errors Line 223: Expected 1 errors -Line 224: Expected 1 errors +Line 225: Expected 1 errors Line 226: Expected 1 errors -Line 227: Expected 1 errors Line 228: Expected 1 errors +Line 229: Expected 1 errors +Line 230: Expected 1 errors +Line 238: Expected 1 errors +Line 240: Expected 1 errors +Line 241: Expected 1 errors Line 243: Expected 1 errors Line 244: Expected 1 errors -Line 246: Expected 1 errors -Line 247: Expected 1 errors -Line 249: Expected 1 errors -Line 250: Expected 1 errors -Line 251: Expected 1 errors -Line 252: Expected 1 errors +Line 245: Expected 1 errors +Line 264: Expected 1 errors +Line 265: Expected 1 errors +Line 267: Expected 1 errors +Line 268: Expected 1 errors +Line 270: Expected 1 errors +Line 271: Expected 1 errors +Line 272: Expected 1 errors +Line 273: Expected 1 errors Line 23: Unexpected errors ['callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 27: Unexpected errors ['callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 166: Unexpected errors ['callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 170: Unexpected errors ['callables_kwargs.py:170: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 174: Unexpected errors ['callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 178: Unexpected errors ['callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 182: Unexpected errors ['callables_kwargs.py:182: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] """ diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index fc5b69c33..2d73bf87a 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -5,28 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable whose `**kwa """ conformance_automated = "Fail" errors_diff = """ -Line 210: Expected 1 errors -Line 212: Expected 1 errors -Line 213: Expected 1 errors -Line 215: Expected 1 errors -Line 216: Expected 1 errors -Line 217: Expected 1 errors -Line 221: Expected 1 errors Line 223: Expected 1 errors -Line 224: Expected 1 errors Line 226: Expected 1 errors -Line 227: Expected 1 errors -Line 228: Expected 1 errors -Line 243: Expected 1 errors +Line 229: Expected 1 errors +Line 230: Expected 1 errors +Line 238: Expected 1 errors +Line 241: Expected 1 errors Line 244: Expected 1 errors -Line 246: Expected 1 errors -Line 247: Expected 1 errors -Line 249: Expected 1 errors -Line 250: Expected 1 errors -Line 251: Expected 1 errors -Line 252: Expected 1 errors -Line 155: Unexpected errors ["./callables_kwargs.py:155:0: Incompatible assignment: expected callables_kwargs.TDProtocol7, got function 'callables_kwargs.func7' [incompatible_assignment]"] -Line 156: Unexpected errors ["./callables_kwargs.py:156:0: Incompatible assignment: expected callables_kwargs.TDProtocol8, got function 'callables_kwargs.func7' [incompatible_assignment]"] +Line 245: Expected 1 errors """ output = """ ./callables_kwargs.py:55:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] @@ -43,6 +29,16 @@ output = """ ./callables_kwargs.py:131:21: Parameter v1 overlaps with TypedDict key in **kwargs [invalid_annotation] ./callables_kwargs.py:142:12: Expected TypedDict type inside Unpack[] for **kwargs [invalid_annotation] ./callables_kwargs.py:154:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] -./callables_kwargs.py:155:0: Incompatible assignment: expected callables_kwargs.TDProtocol7, got function 'callables_kwargs.func7' [incompatible_assignment] -./callables_kwargs.py:156:0: Incompatible assignment: expected callables_kwargs.TDProtocol8, got function 'callables_kwargs.func7' [incompatible_assignment] +./callables_kwargs.py:225:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:228:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:240:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:243:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:264:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:265:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:267:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:268:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:270:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:271:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:272:4: Incompatible argument type for label: expected str but got int [incompatible_argument] +./callables_kwargs.py:273:4: Incompatible argument type for label: expected str but got int [incompatible_argument] """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index baef65d46..5eab3ae38 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -10,26 +10,26 @@ Incorrectly rejects assigning a callable without `**kwargs` to a callable whose """ conformance_automated = "Fail" errors_diff = """ -Line 210: Expected 1 errors -Line 212: Expected 1 errors -Line 213: Expected 1 errors -Line 215: Expected 1 errors -Line 216: Expected 1 errors -Line 217: Expected 1 errors -Line 221: Expected 1 errors Line 223: Expected 1 errors -Line 224: Expected 1 errors +Line 225: Expected 1 errors Line 226: Expected 1 errors -Line 227: Expected 1 errors Line 228: Expected 1 errors +Line 229: Expected 1 errors +Line 230: Expected 1 errors +Line 238: Expected 1 errors +Line 240: Expected 1 errors +Line 241: Expected 1 errors Line 243: Expected 1 errors Line 244: Expected 1 errors -Line 246: Expected 1 errors -Line 247: Expected 1 errors -Line 249: Expected 1 errors -Line 250: Expected 1 errors -Line 251: Expected 1 errors -Line 252: Expected 1 errors +Line 245: Expected 1 errors +Line 264: Expected 1 errors +Line 265: Expected 1 errors +Line 267: Expected 1 errors +Line 268: Expected 1 errors +Line 270: Expected 1 errors +Line 271: Expected 1 errors +Line 272: Expected 1 errors +Line 273: Expected 1 errors Line 156: Unexpected errors ["`(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol8` [bad-assignment]"] """ output = """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index e677b7a26..d1255aa34 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -37,33 +37,33 @@ callables_kwargs.py:142:21 - error: Expected TypedDict type argument for Unpack callables_kwargs.py:154:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) -callables_kwargs.py:212:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:225:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:215:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:228:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:223:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:240:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:226:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:243:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:244:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:265:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:247:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:268:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 210: Expected 1 errors -Line 213: Expected 1 errors -Line 216: Expected 1 errors -Line 217: Expected 1 errors -Line 221: Expected 1 errors -Line 224: Expected 1 errors -Line 227: Expected 1 errors -Line 228: Expected 1 errors -Line 243: Expected 1 errors -Line 246: Expected 1 errors -Line 249: Expected 1 errors -Line 250: Expected 1 errors -Line 251: Expected 1 errors -Line 252: Expected 1 errors +Line 223: Expected 1 errors +Line 226: Expected 1 errors +Line 229: Expected 1 errors +Line 230: Expected 1 errors +Line 238: Expected 1 errors +Line 241: Expected 1 errors +Line 244: Expected 1 errors +Line 245: Expected 1 errors +Line 264: Expected 1 errors +Line 267: Expected 1 errors +Line 270: Expected 1 errors +Line 271: Expected 1 errors +Line 272: Expected 1 errors +Line 273: Expected 1 errors """ diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 66153ff91..34e9e0cc3 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -5,14 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable that has no Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ errors_diff = """ -Line 210: Expected 1 errors -Line 213: Expected 1 errors -Line 216: Expected 1 errors -Line 217: Expected 1 errors -Line 221: Expected 1 errors -Line 224: Expected 1 errors -Line 227: Expected 1 errors -Line 228: Expected 1 errors +Line 223: Expected 1 errors +Line 226: Expected 1 errors +Line 229: Expected 1 errors +Line 230: Expected 1 errors +Line 238: Expected 1 errors +Line 241: Expected 1 errors +Line 244: Expected 1 errors +Line 245: Expected 1 errors """ output = """ callables_kwargs.py:55:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` @@ -30,16 +30,16 @@ callables_kwargs.py:123:19: error[invalid-assignment] Object of type `def func1( callables_kwargs.py:131:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation callables_kwargs.py:142:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` callables_kwargs.py:154:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6` -callables_kwargs.py:212:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:215:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:223:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:226:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:243:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:244:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:246:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:247:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:249:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` -callables_kwargs.py:250:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` -callables_kwargs.py:251:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:252:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:225:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:228:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:240:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:243:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:264:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:265:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:267:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:268:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:270:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:271:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:272:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:273:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 0b4f236a7..d9d24e930 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -5,22 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable whose `**kwa """ conformance_automated = "Fail" errors_diff = """ -Line 210: Expected 1 errors -Line 212: Expected 1 errors -Line 213: Expected 1 errors -Line 215: Expected 1 errors -Line 216: Expected 1 errors -Line 217: Expected 1 errors -Line 221: Expected 1 errors Line 223: Expected 1 errors -Line 224: Expected 1 errors Line 226: Expected 1 errors -Line 227: Expected 1 errors -Line 228: Expected 1 errors -Line 243: Expected 1 errors -Line 246: Expected 1 errors -Line 155: Unexpected errors ['callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment]'] -Line 156: Unexpected errors ['callables_kwargs.py:156: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol8") [assignment]'] +Line 229: Expected 1 errors +Line 230: Expected 1 errors +Line 238: Expected 1 errors +Line 241: Expected 1 errors +Line 244: Expected 1 errors +Line 245: Expected 1 errors """ output = """ callables_kwargs.py:55: error: Missing named argument "v1" for "func1" [call-arg] @@ -43,12 +35,16 @@ callables_kwargs.py:123: error: Incompatible types in assignment (expression has callables_kwargs.py:131: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict [misc] callables_kwargs.py:154: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol6") [assignment] -callables_kwargs.py:155: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol7") [assignment] -callables_kwargs.py:156: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol8") [assignment] -callables_kwargs.py:244: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:247: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:249: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] -callables_kwargs.py:250: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] -callables_kwargs.py:251: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:252: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:225: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] +callables_kwargs.py:228: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] +callables_kwargs.py:240: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] +callables_kwargs.py:243: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] +callables_kwargs.py:264: error: Too many arguments for "takes_name" [call-arg] +callables_kwargs.py:265: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:267: error: Too many arguments for "takes_name" [call-arg] +callables_kwargs.py:268: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:270: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:271: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:272: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:273: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index df1b3b638..113753c9a 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -179,6 +179,10 @@ class TDExtraItemsNever(TypedDict, extra_items=Never): name: str +class TDExtraItemsObject(TypedDict, extra_items=object): + name: str + + def takes_name(name: str) -> None: ... @@ -187,6 +191,10 @@ def takes_name_kwargs(name: str, **kwargs) -> None: ... +def takes_name_object_kwargs(name: str, **kwargs: object) -> None: + ... + + def takes_name_str_kwargs(name: str, **kwargs: str) -> None: ... @@ -203,6 +211,11 @@ def takes_closed(**kwargs: Unpack[TDClosed]) -> None: ... +# Equivalent to `def takes_extra_items_object(*, name: str, **kwargs: object)`. +def takes_extra_items_object(**kwargs: Unpack[TDExtraItemsObject]) -> None: + ... + + # > It is only safe to unpack a non-:term:`closed` TypedDict in a function call if that function has # > ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. @@ -215,6 +228,10 @@ def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> No takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible takes_closed(**value) # E: a subtype may contain unknown keys takes_closed(**kwargs) # E: a subtype may contain unknown keys + takes_name_object_kwargs(**value) + takes_name_object_kwargs(**kwargs) + takes_extra_items_object(**value) + takes_extra_items_object(**kwargs) def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> None: @@ -226,6 +243,10 @@ def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> Non takes_name_str_kwargs(**kwargs) # E: extra items type is not compatible takes_closed(**value) # E: a subtype may contain unknown keys takes_closed(**kwargs) # E: a subtype may contain unknown keys + takes_name_object_kwargs(**value) + takes_name_object_kwargs(**kwargs) + takes_extra_items_object(**value) + takes_extra_items_object(**kwargs) def kwargs_closed(value: TDClosed, **kwargs: Unpack[TDClosed]) -> None: @@ -250,6 +271,8 @@ def kwargs_extra_items(value: TDExtraItems, **kwargs: Unpack[TDExtraItems]) -> N takes_closed(**kwargs) # E: extra items may be present takes_optional_label_int_kwargs(**value) # E: extra items type is not compatible w/ `label` param takes_optional_label_int_kwargs(**kwargs) # E: extra items type is not compatible w/ `label` param + takes_extra_items_object(**value) + takes_extra_items_object(**kwargs) def kwargs_extra_items_never(value: TDExtraItemsNever, **kwargs: Unpack[TDExtraItemsNever]) -> None: From dd9df61a57db37c97166fcac6f0263c88a8c2948 Mon Sep 17 00:00:00 2001 From: yangdanny97 Date: Fri, 28 Aug 2026 23:28:38 -0400 Subject: [PATCH 11/16] update spec wording --- docs/spec/callables.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index 93a563b0a..c544019ac 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -415,9 +415,19 @@ argument will be passed to the ``takes_name`` function. Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. - -- If the function being called has ``**kwargs``, checkers should error if the TypedDict's :term:`extra items` are not assignable to the type of ``**kwargs``. For this rule, :term:`open` TypedDicts are treated as having extra items of type ``object``. -- If the function being called does not have ``**kwargs``, checkers should error if the TypedDict is :term:`open`, and should error if the TypedDict declares non-``Never`` :term:`extra items`. +For these rules, :term:`open` TypedDicts are treated as having :term:`extra items` of +type ``object``. + +- If the callee has non-unpacked ``**kwargs``, checkers should error if the TypedDict's + :term:`extra items` are not assignable to the type of ``**kwargs``. +- If the callee has unpacked ``**kwargs`` (``**kwargs: Unpack[TD]``), checkers should + error if the TypedDict's :term:`extra items` are not assignable to ``TD``'s extra + items, treating a :term:`closed` ``TD`` as accepting no extra items. +- If the callee does not have ``**kwargs``, checkers should error if the TypedDict is + :term:`open`, and should error if the TypedDict declares non-``Never`` + :term:`extra items`. + +Additionally, the type of :term:`extra items` must be assignable to any keyword parameters the function call does not provide. In cases similar to the ``bar`` function above the problem could be worked around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired From b45c1058f670da7040fd859c9c9557091369f99d Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Tue, 24 Nov 2026 18:48:46 -0500 Subject: [PATCH 12/16] regenerate conformance results after rebase Co-Authored-By: Claude Opus 5.5 --- .../results/mypy/callables_kwargs.toml | 10 +- .../results/pyrefly/callables_kwargs.toml | 24 +- .../results/pyright/callables_kwargs.toml | 6 +- conformance/results/results.html | 325 ++++++------------ 4 files changed, 114 insertions(+), 251 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 41996bd9d..43d98bab2 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -1,7 +1,7 @@ conformant = "Partial" notes = """ Allows callable without kwargs to be assigned to callable with unpacked kwargs. -Does not support the `closed` and `extra_items` TypedDict class arguments. +Does not support the `extra_items` TypedDict class argument. Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. @@ -10,12 +10,11 @@ Does not reject unpacking a TypedDict that sets `extra_items` in a call to a cal Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ output = """ -callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:55: error: Missing named argument "v1" for "func1" [call-arg] callables_kwargs.py:55: error: Missing named argument "v3" for "func1" [call-arg] callables_kwargs.py:60: error: Unexpected keyword argument "v4" for "func1" [call-arg] -callables_kwargs.py:61: error: Too many positional arguments for "func1" [misc] +callables_kwargs.py:61: error: Too many positional arguments for "func1" [call-arg] callables_kwargs.py:67: error: Argument 1 to "func1" has incompatible type "**dict[str, str]"; expected "int" [arg-type] callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "int" [arg-type] callables_kwargs.py:70: error: Argument 1 to "func1" has incompatible type "**dict[str, object]"; expected "str" [arg-type] @@ -31,8 +30,6 @@ callables_kwargs.py:123: error: Incompatible types in assignment (expression has callables_kwargs.py:123: note: "TDProtocol5.__call__" has type "def __call__(self, v1: int, v3: str) -> None" callables_kwargs.py:131: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict [misc] -callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:170: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] callables_kwargs.py:182: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] @@ -60,10 +57,7 @@ Line 270: Expected 1 errors Line 271: Expected 1 errors Line 272: Expected 1 errors Line 273: Expected 1 errors -Line 23: Unexpected errors ['callables_kwargs.py:23: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 27: Unexpected errors ['callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 166: Unexpected errors ['callables_kwargs.py:166: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 170: Unexpected errors ['callables_kwargs.py:170: error: Unexpected keyword argument "closed" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 174: Unexpected errors ['callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 178: Unexpected errors ['callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 182: Unexpected errors ['callables_kwargs.py:182: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index 5eab3ae38..63bbe3b56 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -2,11 +2,7 @@ conformant = "Partial" notes = """ Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. -Does not check the type of an unpacked TypedDict's extra items against the target callable's `**kwargs` annotation. -Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. -Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. -Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. -Incorrectly rejects assigning a callable without `**kwargs` to a callable whose `**kwargs` is typed with a TypedDict that sets `extra_items=Never`. +Does not treat an open TypedDict as having extra items of type `object` when checking against the target callable's `**kwargs` annotation. """ conformance_automated = "Fail" errors_diff = """ @@ -22,15 +18,6 @@ Line 241: Expected 1 errors Line 243: Expected 1 errors Line 244: Expected 1 errors Line 245: Expected 1 errors -Line 264: Expected 1 errors -Line 265: Expected 1 errors -Line 267: Expected 1 errors -Line 268: Expected 1 errors -Line 270: Expected 1 errors -Line 271: Expected 1 errors -Line 272: Expected 1 errors -Line 273: Expected 1 errors -Line 156: Unexpected errors ["`(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol8` [bad-assignment]"] """ output = """ ERROR callables_kwargs.py:55:10-12: Missing argument `v1` in function `func1` [missing-argument] @@ -50,5 +37,12 @@ ERROR callables_kwargs.py:123:19-24: `(**kwargs: Unpack[TD2]) -> None` is not as ERROR callables_kwargs.py:131:20-41: TypedDict key 'v1' in **kwargs overlaps with parameter 'v1' [bad-function-definition] ERROR callables_kwargs.py:142:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] ERROR callables_kwargs.py:154:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] -ERROR callables_kwargs.py:156:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol8` [bad-assignment] +ERROR callables_kwargs.py:264:16-23: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] +ERROR callables_kwargs.py:265:27-34: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:267:16-24: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] +ERROR callables_kwargs.py:268:27-35: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:270:18-25: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] +ERROR callables_kwargs.py:271:18-26: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] +ERROR callables_kwargs.py:272:37-44: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:273:37-45: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index d1255aa34..17c922231 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -29,9 +29,9 @@ callables_kwargs.py:122:19 - error: Type "(**kwargs: **TD2) -> None" is not assi     Extra parameter "v3" (reportAssignmentType) callables_kwargs.py:123:19 - error: Type "(**kwargs: **TD2) -> None" is not assignable to declared type "TDProtocol5"   Type "(**kwargs: **TD2) -> None" is not assignable to type "(v1: int, v3: str) -> None" -    Function accepts too many positional parameters; expected 0 but received 2 -      Extra parameter "v1" -      Extra parameter "v3" (reportAssignmentType) +    Function accepts too few positional parameters; expected 2 but received 0 +      Parameter "v1" is missing default argument +      Parameter "v3" is missing default argument (reportAssignmentType) callables_kwargs.py:131:30 - error: Typed dictionary overlaps with keyword parameter: v1 (reportGeneralTypeIssues) callables_kwargs.py:142:21 - error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues) callables_kwargs.py:154:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6" diff --git a/conformance/results/results.html b/conformance/results/results.html index c9ac5f826..ac25d7aa3 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -264,12 +264,12 @@

      Python Type System Conformance Test Results

      - mypy 2.1.0 + mypy 2.4.0 pycroscope 0.5.0 - pyrefly 1.3.0-dev.1 - pyright 1.1.410 - ty 0.0.75 - zuban 0.9.2 + pyrefly 1.5.0 + pyright 1.1.414 + ty 0.0.108 + zuban 0.10.2 @@ -294,36 +294,52 @@

      Python Type System Conformance Test Results

      • Does not report error for a forward reference that is not enclosed in quotes.
      • Does not report error for use of quoted type with | operator (runtime error).
      • -
      • Incorrectly generates error for quoted type defined in class scope.
      • +
      • Resolves some forward references in type annotations in classes at the point of definition instead of end-of-scope
      Partial
      • Fails to reject "x" | int annotations that fail at runtime.
      • +
      • Resolves forward references in type annotations in classes at the point of definition instead of end-of-scope
      • Rejects some valid quoted annotations.
      + Pass Partial
        -
      • Types in quotes incorrectly refer to shadowing class member.
      • -
      • Does not reject some type forms that require quotes.
      • +
      • Prefers to resolve forward references in classes outside of the class instead of end-of-scope
      Pass + Pass + + + annotations_future_import Partial Partial
        -
      • Incorrectly generates error for quoted type defined in class scope.
      • +
      • Forward references to nested classes are not resolved
      • +
      • Nested classes are resolved, but its type is Any
      • +
      • Resolves some class annotations to outer names instead of shadowing class bindings
      + Pass + + Partial +
        +
      • Prefers to resolve forward references in classes outside of the class instead of end-of-scope
      • +
      + + Pass + Pass annotations_generators @@ -374,12 +390,12 @@

      Python Type System Conformance Test Results

      - 4 / 5 • 80.0% - 4 / 5 • 80.0% - 4.5 / 5 • 90.0% - 5 / 5 • 100.0% - 4.5 / 5 • 90.0% - 4.5 / 5 • 90.0% + 4.5 / 6 • 75.0% + 4.5 / 6 • 75.0% + 6 / 6 • 100.0% + 5 / 6 • 83.3% + 6 / 6 • 100.0% + 6 / 6 • 100.0% @@ -403,7 +419,7 @@

      Python Type System Conformance Test Results

    Pass - Unsupported + Pass Pass Pass @@ -412,7 +428,7 @@

    Python Type System Conformance Test Results

    0.5 / 1 • 50.0% 0.5 / 1 • 50.0% 1 / 1 • 100.0% - 0 / 1 • 0.0% + 1 / 1 • 100.0% 1 / 1 • 100.0% 1 / 1 • 100.0% @@ -467,7 +483,7 @@

    Python Type System Conformance Test Results

    specialtypes_sentinels - Unsupported + Pass Pass Pass @@ -495,7 +511,6 @@

    Python Type System Conformance Test Results

    Partial
      -
    • Allows arbitrary attributes to be accessed on TA where TA = typing.Type[typing.Any] or TA = type[typing.Any].
    • Treats type equivalently to type[object] rather than type[typing.Any].
    @@ -503,7 +518,7 @@

    Python Type System Conformance Test Results

    - 4.5 / 6 • 75.0% + 5.5 / 6 • 91.7% 5.5 / 6 • 91.7% 6 / 6 • 100.0% 5.5 / 6 • 91.7% @@ -537,12 +552,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Incorrectly allows constrained type variables to be solved to a union of their constraints.
    • -
    - + Pass Pass @@ -557,14 +567,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not forbid a TypeVar immediately following a TypeVarTuple in a parameter list from having a default.
    • -
    • Does not accept a TypeVarTuple default that unpacks another in-scope TypeVarTuple.
    • -
    • Does not correctly specialize a generic that combines a TypeVarTuple with a defaulted ParamSpec.
    • -
    - + Pass Pass @@ -583,20 +586,10 @@

    Python Type System Conformance Test Results

    generics_defaults_specialization - - Partial -
      -
    • Does not correctly resolve defaults when classes are used directly.
    • -
    - Pass Pass - - Partial -
      -
    • Allows incorrect assignment to type[].
    • -
    - + Pass + Pass Pass Pass @@ -604,7 +597,7 @@

    Python Type System Conformance Test Results

    generics_mixed_variance_inference Pass Pass - Unsupported + Pass Unsupported Pass Pass @@ -654,14 +647,9 @@

    Python Type System Conformance Test Results

    generics_paramspec_variance Unsupported Pass + Pass Unsupported - Unsupported - - Partial -
      -
    • Does not error when a ParamSpec is used in a position that violates its explicit variance.
    • -
    - + Pass Pass @@ -670,13 +658,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not reject list[T]() in the global scope, where T is an unbound type variable.
    • -
    • Does not reject alias: TypeAlias = list[T] in the body scope of a class generic over a type variable T.
    • -
    - + Pass Pass @@ -748,7 +730,12 @@

    Python Type System Conformance Test Results

    generics_syntax_declarations - Pass + + Partial +
      +
    • Doesn't flag TypeVar with empty constraints.
    • +
    + Pass Pass Pass @@ -794,12 +781,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not reject access of generic instance variable from the class object.
    • -
    - + Pass Pass @@ -812,12 +794,7 @@

    Python Type System Conformance Test Results

    Pass Pass - - Partial -
      -
    • Does not correctly solve TypeVarTuple with heterogeneous bounds.
    • -
    - + Pass Pass Pass @@ -831,12 +808,7 @@

    Python Type System Conformance Test Results

    Pass Pass - - Partial -
      -
    • Does not correctly solve TypeVarTuple with heterogeneous bounds.
    • -
    - + Pass Pass Pass @@ -895,14 +867,9 @@

    Python Type System Conformance Test Results

    generics_typevartuple_variance Unsupported Pass + Pass Unsupported - Unsupported - - Partial -
      -
    • Does not error when a TypeVarTuple is used in a position that violates its explicit variance.
    • -
    - + Pass Pass @@ -953,9 +920,9 @@

    Python Type System Conformance Test Results

    23.5 / 33 • 71.2% 33 / 33 • 100.0% + 33 / 33 • 100.0% 30 / 33 • 90.9% - 28.5 / 33 • 86.4% - 30 / 33 • 90.9% + 33 / 33 • 100.0% 33 / 33 • 100.0% @@ -1066,13 +1033,7 @@

    Python Type System Conformance Test Results

  • the incompatible constructor overrides in ChildC2 are not flagged.
  • - - Partial -
      -
    • Does not honor @override compatibility checks for __init__ and __new__:
    • -
    • the incompatible constructor overrides in ChildC2 are not flagged.
    • -
    - + Pass Pass @@ -1081,7 +1042,7 @@

    Python Type System Conformance Test Results

    2 / 2 • 100.0% 2 / 2 • 100.0% 1.5 / 2 • 75.0% - 1.5 / 2 • 75.0% + 2 / 2 • 100.0% 2 / 2 • 100.0% @@ -1102,12 +1063,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not emit a diagnostic if a type alias to a union, in which every element of the union is implicitly specialized with Unknown, is invalidly specialized again.
    • -
    - + Pass Pass @@ -1122,13 +1078,7 @@

    Python Type System Conformance Test Results

    Pass Pass - - Partial -
      -
    • Does not reject variables with Any or Unknown types when used as implicit type aliases.
    • -
    • Falls short on full syntactic validation of type aliases.
    • -
    - + Pass Pass @@ -1151,7 +1101,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - Unsupported + Pass Pass @@ -1166,12 +1116,7 @@

    Python Type System Conformance Test Results

    Pass Pass - - Partial -
      -
    • Does not reject a generic type alias that recursively specializes itself with different type arguments.
    • -
    - + Pass Pass @@ -1186,12 +1131,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not reject cyclically defined TypeAliasType aliases.
    • -
    - + Pass Pass @@ -1209,7 +1149,7 @@

    Python Type System Conformance Test Results

    6 / 7 • 85.7% 7 / 7 • 100.0% 7 / 7 • 100.0% - 4 / 7 • 57.1% + 7 / 7 • 100.0% 7 / 7 • 100.0% @@ -1337,11 +1277,11 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Unsupported + + Partial
      -
    • Allows implicitly abstract protocol methods to be called via super() on a protocol subclass.
    • -
    • Allows instantiation of abstract subclasses of protocol classes.
    • +
    • Allows abstract protocol methods with no default implementation to be called via super() on a protocol subclass.
    • +
    • Allows instantiation of protocol subclasses with uninitialized ClassVar members.
    Pass @@ -1360,7 +1300,7 @@

    Python Type System Conformance Test Results

    Partial
      -
    • Only partially supports @property protocol members.
    • +
    • Does not reject incompatible non-generic implementations of generic protocol methods.
    Pass @@ -1371,12 +1311,7 @@

    Python Type System Conformance Test Results

    Pass Pass Pass - - Partial -
      -
    • Does not reject attempted instantiation of abstract subclasses of protocols.
    • -
    - + Pass Pass @@ -1448,12 +1383,7 @@

    Python Type System Conformance Test Results

    Pass - - Partial -
      -
    • Doesn't support variance keywords to ParamSpec
    • -
    - + Pass Partial
      @@ -1467,9 +1397,9 @@

      Python Type System Conformance Test Results

      9.5 / 11 • 86.4% 10 / 11 • 90.9% + 11 / 11 • 100.0% 10.5 / 11 • 95.5% - 10.5 / 11 • 95.5% - 7.5 / 11 • 68.2% + 8.5 / 11 • 77.3% 11 / 11 • 100.0% @@ -1500,7 +1430,7 @@

      Python Type System Conformance Test Results

      Partial
      • Allows callable without kwargs to be assigned to callable with unpacked kwargs.
      • -
      • Does not support the closed and extra_items TypedDict class arguments.
      • +
      • Does not support the extra_items TypedDict class argument.
      • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
      • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
      • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
      • @@ -1521,11 +1451,7 @@

        Python Type System Conformance Test Results

        • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
        • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
        • -
        • Does not check the type of an unpacked TypedDict's extra items against the target callable's **kwargs annotation.
        • -
        • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
        • -
        • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
        • -
        • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
        • -
        • Incorrectly rejects assigning a callable without **kwargs to a callable whose **kwargs is typed with a TypedDict that sets extra_items=Never.
        • +
        • Does not treat an open TypedDict as having extra items of type object when checking against the target callable's **kwargs annotation.
        @@ -1603,7 +1529,6 @@

        Python Type System Conformance Test Results

        Partial
        • Does not reject invalid argument types to an inherited constructor in a specialized subclass of a generic superclass.
        • -
        • Does not reject class-scoped type variables used in the self annotation.
        Pass @@ -1770,18 +1695,12 @@

        Python Type System Conformance Test Results

      • 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 evaluate Any in some cases where overload is ambiguous.
      • Evaluates Any in some cases where overload is not ambiguous.
      Pass Pass - - Partial -
        -
      • Does not evaluate Any in some cases where overload is ambiguous.
      • -
      - + Pass Pass Pass @@ -1790,7 +1709,7 @@

      Python Type System Conformance Test Results

      3.5 / 5 • 70.0% 3.5 / 5 • 70.0% 5 / 5 • 100.0% - 4.5 / 5 • 90.0% + 5 / 5 • 100.0% 5 / 5 • 100.0% 5 / 5 • 100.0% @@ -1828,33 +1747,11 @@

      Python Type System Conformance Test Results

      dataclasses_descriptors - - Partial -
        -
      • Assumes descriptor behavior only when field is assigned in class body.
      • -
      • Does not correctly evaluate type of descriptor access.
      • -
      - - - Partial - - - - Partial -
        -
      • Assumes descriptor behavior only when field is assigned in class body
      • -
      • Doesn't allow non-data descriptors or data descriptors with differing __get__ and __set__ types
      • -
      - Pass - - Partial -
        -
      • Only infers a descriptor __get__ method as being called when a descriptor attribute is accessed on an instance if the descriptor attribute is present in the class namespace.
      • -
      - + Pass + Pass + Pass + Pass Pass @@ -2033,11 +1930,11 @@

      Python Type System Conformance Test Results

      - 11.5 / 16 • 71.9% - 15.5 / 16 • 96.9% - 15.5 / 16 • 96.9% + 12 / 16 • 75.0% + 16 / 16 • 100.0% + 16 / 16 • 100.0% + 16 / 16 • 100.0% 16 / 16 • 100.0% - 15.5 / 16 • 96.9% 16 / 16 • 100.0% @@ -2071,12 +1968,7 @@

      Python Type System Conformance Test Results

      Pass Pass - - Partial -
        -
      • Does not support version-conditional items in TypedDict definitions.
      • -
      - + Pass Pass Pass @@ -2206,7 +2098,7 @@

      Python Type System Conformance Test Results

      11.5 / 14 • 82.1% 14 / 14 • 100.0% 14 / 14 • 100.0% - 13.5 / 14 • 96.4% + 14 / 14 • 100.0% 14 / 14 • 100.0% 14 / 14 • 100.0% @@ -2362,12 +2254,7 @@

      Python Type System Conformance Test Results

      Pass Pass - - Partial -
        -
      • Does not treat a complete union of all literal members as equivalent to the enum type.
      • -
      - + Pass Pass Pass @@ -2429,7 +2316,7 @@

      Python Type System Conformance Test Results

      4.5 / 6 • 75.0% 6 / 6 • 100.0% 6 / 6 • 100.0% - 5.5 / 6 • 91.7% + 6 / 6 • 100.0% 6 / 6 • 100.0% 6 / 6 • 100.0% @@ -2498,14 +2385,7 @@

      Python Type System Conformance Test Results

      Pass Pass Pass - - Partial -
        -
      • Does not detect calls to deprecated overloads.
      • -
      • Does not detect implicit calls to deprecated dunder methods, for example via operators.
      • -
      • Does not detect accesses of, or attempts to set, deprecated properties.
      • -
      - + Pass Pass @@ -2513,12 +2393,7 @@

      Python Type System Conformance Test Results

      Pass Pass Pass - - Unsupported -
        -
      • Does not support PEP 800 disjoint-base semantics.
      • -
      - + Pass Pass Pass @@ -2612,8 +2487,8 @@

      Python Type System Conformance Test Results

      10 / 11 • 90.9% 11 / 11 • 100.0% 11 / 11 • 100.0% - 10 / 11 • 90.9% - 10.5 / 11 • 95.5% + 11 / 11 • 100.0% + 11 / 11 • 100.0% 11 / 11 • 100.0% @@ -2652,12 +2527,12 @@

      Python Type System Conformance Test Results

      - 108.5 / 145 • 74.8% - 137.5 / 145 • 94.8% - 140 / 145 • 96.6% - 135 / 145 • 93.1% - 131.5 / 145 • 90.7% - 144 / 145 • 99.3% + 110.5 / 146 • 75.7% + 138.5 / 146 • 94.9% + 145.5 / 146 • 99.7% + 140 / 146 • 95.9% + 141.5 / 146 • 96.9% + 145.5 / 146 • 99.7% From 9025a121eb2dd50ae3088bfa3204ea6e06d4b314 Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Tue, 24 Nov 2026 22:21:04 -0500 Subject: [PATCH 13/16] add additional test cases and spec clarifications --- .../results/mypy/callables_kwargs.toml | 57 ++++++++++--------- .../results/pycroscope/callables_kwargs.toml | 42 +++++++------- .../results/pyrefly/callables_kwargs.toml | 42 +++++++------- .../results/pyright/callables_kwargs.toml | 55 +++++++++++------- conformance/results/ty/callables_kwargs.toml | 42 +++++++------- .../results/zuban/callables_kwargs.toml | 46 ++++++++------- conformance/tests/callables_kwargs.py | 54 ++++++++++++++++++ docs/spec/callables.rst | 37 ++++++++++++ 8 files changed, 249 insertions(+), 126 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 43d98bab2..0f84a4ca2 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -30,35 +30,40 @@ callables_kwargs.py:123: error: Incompatible types in assignment (expression has callables_kwargs.py:123: note: "TDProtocol5.__call__" has type "def __call__(self, v1: int, v3: str) -> None" callables_kwargs.py:131: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict [misc] -callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] -callables_kwargs.py:182: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:210: error: Incompatible types in assignment (expression has type "def func8(**kwargs: **TDBase) -> None", variable has type "TDProtocol10") [assignment] +callables_kwargs.py:210: note: "TDProtocol10.__call__" has type "def __call__(self, **kwargs: **TDChild) -> None" +callables_kwargs.py:228: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:232: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] +callables_kwargs.py:236: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] """ conformance_automated = "Fail" errors_diff = """ Line 154: Expected 1 errors -Line 223: Expected 1 errors -Line 225: Expected 1 errors -Line 226: Expected 1 errors -Line 228: Expected 1 errors -Line 229: Expected 1 errors -Line 230: Expected 1 errors -Line 238: Expected 1 errors -Line 240: Expected 1 errors -Line 241: Expected 1 errors -Line 243: Expected 1 errors -Line 244: Expected 1 errors -Line 245: Expected 1 errors -Line 264: Expected 1 errors -Line 265: Expected 1 errors -Line 267: Expected 1 errors -Line 268: Expected 1 errors -Line 270: Expected 1 errors -Line 271: Expected 1 errors -Line 272: Expected 1 errors -Line 273: Expected 1 errors +Line 174: Expected 1 errors +Line 209: Expected 1 errors +Line 277: Expected 1 errors +Line 279: Expected 1 errors +Line 280: Expected 1 errors +Line 282: Expected 1 errors +Line 283: Expected 1 errors +Line 284: Expected 1 errors +Line 292: Expected 1 errors +Line 294: Expected 1 errors +Line 295: Expected 1 errors +Line 297: Expected 1 errors +Line 298: Expected 1 errors +Line 299: Expected 1 errors +Line 318: Expected 1 errors +Line 319: Expected 1 errors +Line 321: Expected 1 errors +Line 322: Expected 1 errors +Line 324: Expected 1 errors +Line 325: Expected 1 errors +Line 326: Expected 1 errors +Line 327: Expected 1 errors Line 27: Unexpected errors ['callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 174: Unexpected errors ['callables_kwargs.py:174: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 178: Unexpected errors ['callables_kwargs.py:178: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] -Line 182: Unexpected errors ['callables_kwargs.py:182: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 210: Unexpected errors ['callables_kwargs.py:210: error: Incompatible types in assignment (expression has type "def func8(**kwargs: **TDBase) -> None", variable has type "TDProtocol10") [assignment]'] +Line 228: Unexpected errors ['callables_kwargs.py:228: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 232: Unexpected errors ['callables_kwargs.py:232: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] +Line 236: Unexpected errors ['callables_kwargs.py:236: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] """ diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index 2d73bf87a..b46312e50 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -5,14 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable whose `**kwa """ conformance_automated = "Fail" errors_diff = """ -Line 223: Expected 1 errors -Line 226: Expected 1 errors -Line 229: Expected 1 errors -Line 230: Expected 1 errors -Line 238: Expected 1 errors -Line 241: Expected 1 errors -Line 244: Expected 1 errors -Line 245: Expected 1 errors +Line 277: Expected 1 errors +Line 280: Expected 1 errors +Line 283: Expected 1 errors +Line 284: Expected 1 errors +Line 292: Expected 1 errors +Line 295: Expected 1 errors +Line 298: Expected 1 errors +Line 299: Expected 1 errors """ output = """ ./callables_kwargs.py:55:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] @@ -29,16 +29,18 @@ output = """ ./callables_kwargs.py:131:21: Parameter v1 overlaps with TypedDict key in **kwargs [invalid_annotation] ./callables_kwargs.py:142:12: Expected TypedDict type inside Unpack[] for **kwargs [invalid_annotation] ./callables_kwargs.py:154:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] -./callables_kwargs.py:225:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:228:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:240:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:243:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:264:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:265:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:267:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:268:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:270:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:271:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:272:4: Incompatible argument type for label: expected str but got int [incompatible_argument] -./callables_kwargs.py:273:4: Incompatible argument type for label: expected str but got int [incompatible_argument] +./callables_kwargs.py:174:4: Value of method incompatible with base class callables_kwargs.BaseUnpacked [incompatible_override] +./callables_kwargs.py:209:0: Incompatible assignment: expected callables_kwargs.TDProtocol9, got function 'callables_kwargs.func9' [incompatible_assignment] +./callables_kwargs.py:279:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:282:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:294:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:297:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:318:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:319:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:321:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:322:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:324:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:325:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:326:4: Incompatible argument type for label: expected str but got int [incompatible_argument] +./callables_kwargs.py:327:4: Incompatible argument type for label: expected str but got int [incompatible_argument] """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index 63bbe3b56..cb1afbfb5 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -6,18 +6,19 @@ Does not treat an open TypedDict as having extra items of type `object` when che """ conformance_automated = "Fail" errors_diff = """ -Line 223: Expected 1 errors -Line 225: Expected 1 errors -Line 226: Expected 1 errors -Line 228: Expected 1 errors -Line 229: Expected 1 errors -Line 230: Expected 1 errors -Line 238: Expected 1 errors -Line 240: Expected 1 errors -Line 241: Expected 1 errors -Line 243: Expected 1 errors -Line 244: Expected 1 errors -Line 245: Expected 1 errors +Line 209: Expected 1 errors +Line 277: Expected 1 errors +Line 279: Expected 1 errors +Line 280: Expected 1 errors +Line 282: Expected 1 errors +Line 283: Expected 1 errors +Line 284: Expected 1 errors +Line 292: Expected 1 errors +Line 294: Expected 1 errors +Line 295: Expected 1 errors +Line 297: Expected 1 errors +Line 298: Expected 1 errors +Line 299: Expected 1 errors """ output = """ ERROR callables_kwargs.py:55:10-12: Missing argument `v1` in function `func1` [missing-argument] @@ -37,12 +38,13 @@ ERROR callables_kwargs.py:123:19-24: `(**kwargs: Unpack[TD2]) -> None` is not as ERROR callables_kwargs.py:131:20-41: TypedDict key 'v1' in **kwargs overlaps with parameter 'v1' [bad-function-definition] ERROR callables_kwargs.py:142:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] ERROR callables_kwargs.py:154:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] -ERROR callables_kwargs.py:264:16-23: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] -ERROR callables_kwargs.py:265:27-34: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] -ERROR callables_kwargs.py:267:16-24: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] -ERROR callables_kwargs.py:268:27-35: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] -ERROR callables_kwargs.py:270:18-25: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] -ERROR callables_kwargs.py:271:18-26: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] -ERROR callables_kwargs.py:272:37-44: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] -ERROR callables_kwargs.py:273:37-45: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:174:9-15: Class member `SubNoKwargs.method` overrides parent class `BaseUnpacked` in an inconsistent manner [bad-override] +ERROR callables_kwargs.py:318:16-23: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] +ERROR callables_kwargs.py:319:27-34: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:321:16-24: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] +ERROR callables_kwargs.py:322:27-35: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:324:18-25: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] +ERROR callables_kwargs.py:325:18-26: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] +ERROR callables_kwargs.py:326:37-44: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:327:37-45: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index 17c922231..ff32ce808 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -37,33 +37,48 @@ callables_kwargs.py:142:21 - error: Expected TypedDict type argument for Unpack callables_kwargs.py:154:19 - error: Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to declared type "TDProtocol6"   Type "(*, v1: int, v3: str, v2: str = "") -> None" is not assignable to type "(**kwargs: **TD2) -> None"     Parameter "**kwargs" has no corresponding parameter (reportAssignmentType) -callables_kwargs.py:225:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:174:9 - error: Method "method" overrides class "BaseUnpacked" in an incompatible manner +  Keyword parameter "extra" type mismatch: base parameter is type "*TDPerson", override parameter is type "bool" +  Parameter "**kwargs" has no corresponding parameter +    "*TDPerson" is not assignable to "bool" (reportIncompatibleMethodOverride) +callables_kwargs.py:209:20 - error: Type "(**kwargs: **TDChild) -> None" is not assignable to declared type "TDProtocol9" +  Type "(**kwargs: **TDChild) -> None" is not assignable to type "(**kwargs: **TDBase) -> None" +    Parameter 1: type "*TDBase" is incompatible with type "int" +      "*TDBase" is not assignable to "int" +    Parameter 1: type "*TDBase" is incompatible with type "*TDChild" +      "y" is missing from "*TDBase" (reportAssignmentType) +callables_kwargs.py:210:21 - error: Type "(**kwargs: **TDBase) -> None" is not assignable to declared type "TDProtocol10" +  Type "(**kwargs: **TDBase) -> None" is not assignable to type "(**kwargs: **TDChild) -> None" +    Parameter 1: type "int" is incompatible with type "*TDBase" +      "int" is not assignable to "*TDBase" (reportAssignmentType) +callables_kwargs.py:279:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:228:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:282:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:240:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:294:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:243:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:297:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:265:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:319:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:268:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:322:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 223: Expected 1 errors -Line 226: Expected 1 errors -Line 229: Expected 1 errors -Line 230: Expected 1 errors -Line 238: Expected 1 errors -Line 241: Expected 1 errors -Line 244: Expected 1 errors -Line 245: Expected 1 errors -Line 264: Expected 1 errors -Line 267: Expected 1 errors -Line 270: Expected 1 errors -Line 271: Expected 1 errors -Line 272: Expected 1 errors -Line 273: Expected 1 errors +Line 277: Expected 1 errors +Line 280: Expected 1 errors +Line 283: Expected 1 errors +Line 284: Expected 1 errors +Line 292: Expected 1 errors +Line 295: Expected 1 errors +Line 298: Expected 1 errors +Line 299: Expected 1 errors +Line 318: Expected 1 errors +Line 321: Expected 1 errors +Line 324: Expected 1 errors +Line 325: Expected 1 errors +Line 326: Expected 1 errors +Line 327: Expected 1 errors +Line 210: Unexpected errors ['callables_kwargs.py:210:21 - error: Type "(**kwargs: **TDBase) -> None" is not assignable to declared type "TDProtocol10"'] """ diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 34e9e0cc3..1b5cf53b9 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -5,14 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable that has no Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ errors_diff = """ -Line 223: Expected 1 errors -Line 226: Expected 1 errors -Line 229: Expected 1 errors -Line 230: Expected 1 errors -Line 238: Expected 1 errors -Line 241: Expected 1 errors -Line 244: Expected 1 errors -Line 245: Expected 1 errors +Line 277: Expected 1 errors +Line 280: Expected 1 errors +Line 283: Expected 1 errors +Line 284: Expected 1 errors +Line 292: Expected 1 errors +Line 295: Expected 1 errors +Line 298: Expected 1 errors +Line 299: Expected 1 errors """ output = """ callables_kwargs.py:55:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` @@ -30,16 +30,18 @@ callables_kwargs.py:123:19: error[invalid-assignment] Object of type `def func1( callables_kwargs.py:131:20: error[invalid-type-form] Parameter `v1` overlaps with unpacked TypedDict key in `**kwargs` annotation callables_kwargs.py:142:21: error[invalid-type-form] Unpacked value for `**kwargs` must be a TypedDict, not `T@func6` callables_kwargs.py:154:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6` -callables_kwargs.py:225:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:228:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:240:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:243:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:264:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:265:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:267:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:268:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:270:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` -callables_kwargs.py:271:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` -callables_kwargs.py:272:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:273:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:174:9: error[incompatible-method-override] Invalid override of method `method`: Definition is incompatible with `BaseUnpacked.method` +callables_kwargs.py:209:20: error[invalid-assignment] Object of type `def func9(*, x: int, y: int = ..., **kwargs: object) -> None` is not assignable to `TDProtocol9` +callables_kwargs.py:279:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:282:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:294:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:297:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:318:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:319:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:321:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:322:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:324:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:325:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:326:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:327:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index d9d24e930..6564f4ccf 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -5,14 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable whose `**kwa """ conformance_automated = "Fail" errors_diff = """ -Line 223: Expected 1 errors -Line 226: Expected 1 errors -Line 229: Expected 1 errors -Line 230: Expected 1 errors -Line 238: Expected 1 errors -Line 241: Expected 1 errors -Line 244: Expected 1 errors -Line 245: Expected 1 errors +Line 277: Expected 1 errors +Line 280: Expected 1 errors +Line 283: Expected 1 errors +Line 284: Expected 1 errors +Line 292: Expected 1 errors +Line 295: Expected 1 errors +Line 298: Expected 1 errors +Line 299: Expected 1 errors """ output = """ callables_kwargs.py:55: error: Missing named argument "v1" for "func1" [call-arg] @@ -35,16 +35,22 @@ callables_kwargs.py:123: error: Incompatible types in assignment (expression has callables_kwargs.py:131: error: Overlap between parameter names and ** TypedDict items: "v1" [misc] callables_kwargs.py:142: error: Unpack item in ** parameter must be a TypedDict [misc] callables_kwargs.py:154: error: Incompatible types in assignment (expression has type "def func7(*, v1: int, v3: str, v2: str = ...) -> None", variable has type "TDProtocol6") [assignment] -callables_kwargs.py:225: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] -callables_kwargs.py:228: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] -callables_kwargs.py:240: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] -callables_kwargs.py:243: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] -callables_kwargs.py:264: error: Too many arguments for "takes_name" [call-arg] -callables_kwargs.py:265: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:267: error: Too many arguments for "takes_name" [call-arg] -callables_kwargs.py:268: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:270: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] -callables_kwargs.py:271: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] -callables_kwargs.py:272: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:273: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:174: error: Signature of "method" incompatible with supertype "BaseUnpacked" [override] +callables_kwargs.py:174: note: Superclass: +callables_kwargs.py:174: note: def method(self, **kwargs: Unpack[TDPerson]) -> None +callables_kwargs.py:174: note: Subclass: +callables_kwargs.py:174: note: def method(self, *, name: str, age: int, extra: bool = ...) -> None +callables_kwargs.py:209: error: Incompatible types in assignment (expression has type "def func9(**kwargs: Unpack[TDChild]) -> None", variable has type "TDProtocol9") [assignment] +callables_kwargs.py:279: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] +callables_kwargs.py:282: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] +callables_kwargs.py:294: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] +callables_kwargs.py:297: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] +callables_kwargs.py:318: error: Too many arguments for "takes_name" [call-arg] +callables_kwargs.py:319: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:321: error: Too many arguments for "takes_name" [call-arg] +callables_kwargs.py:322: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:324: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:325: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:326: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:327: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index 113753c9a..6f7fbd742 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -156,6 +156,60 @@ def func7(*, v1: int, v3: str, v2: str = "") -> None: v9: TDProtocol8 = func7 # OK, unpacked TypedDict has extra_items=Never +# An override without **kwargs is not compatible with a base method +# whose **kwargs is an unpacked open TypedDict. + + +class TDPerson(TypedDict): + name: str + age: int + + +class BaseUnpacked: + def method(self, **kwargs: Unpack[TDPerson]) -> None: + ... + + +class SubNoKwargs(BaseUnpacked): + def method(self, *, name: str, age: int, extra: bool = False) -> None: # E: source does not have kwargs + ... + + +# An open TypedDict used to annotate **kwargs is treated as having extra items +# of type `object`, so a callable that accepts additional non-required keys +# cannot be assigned to one that only accepts the base TypedDict's keys. + + +class TDBase(TypedDict): + x: int + + +class TDChild(TDBase, total=False): + y: int + + +class TDProtocol9(Protocol): + def __call__(self, **kwargs: Unpack[TDBase]) -> None: + ... + + +class TDProtocol10(Protocol): + def __call__(self, **kwargs: Unpack[TDChild]) -> None: + ... + + +def func8(**kwargs: Unpack[TDBase]) -> None: + ... + + +def func9(**kwargs: Unpack[TDChild]) -> None: + ... + + +v10: TDProtocol9 = func9 # E: `y` may be passed as an extra item of type `object` +v11: TDProtocol10 = func8 # OK + + # Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#unpacking-a-typeddict-as-keyword-arguments diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index c544019ac..f4763b85c 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -264,6 +264,27 @@ assignable:: accept_animal = accept_dog # WRONG! Expression of type Animal # cannot be assigned to a variable of type Dog. +This also applies when the source function's ``TypedDict`` only adds +:term:`non-required` keys. Because an :term:`open` ``TypedDict`` is +treated as having read-only :term:`extra items` of type ``object`` for the +purposes of :ref:`assignability `, a callable whose +``**kwargs`` is typed with an open ``TypedDict`` may be called with additional +keyword arguments of any type:: + + class Base(TypedDict): + x: int + + class Child(Base, total=False): + y: int + + def accept_base(**kwargs: Unpack[Base]): ... + def accept_child(**kwargs: Unpack[Child]): ... + + accept_child = accept_base # OK! + + accept_base = accept_child # WRONG! accept_base may be called with + # y="a string", which accept_child rejects. + .. _PEP 692 assignment dest no kwargs: Source contains ``**kwargs`` and destination doesn't @@ -366,6 +387,22 @@ traditionally typed ``**kwargs`` aren't checked for keyword names. To summarize, function parameters should behave contravariantly and function return types should behave covariantly. +Method overrides +"""""""""""""""" + +The rules above also apply when checking whether a method that overrides a +method in a base class is compatible with it. As with +:ref:`@override `, the overriding method must be :term:`assignable` +to the overridden method:: + + class Base: + def method(self, **kwargs: Unpack[Animal]): ... + + class Sub(Base): + def method(self, *, name: str): ... # WRONG! Animal is not closed, + # so Base.method may be called + # with additional keyword arguments. + Unpacking a TypedDict as keyword arguments ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 0eed5c3b10b78a4591e5aedc9171296f0a944feb Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Tue, 24 Nov 2026 22:33:43 -0500 Subject: [PATCH 14/16] merge sections --- docs/spec/callables.rst | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index f4763b85c..66dc600a1 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -235,10 +235,10 @@ type may be passed to the function:: f(name="No Country for Old Men", year=2007) # Not OK. Unrecognized item g(name="No Country for Old Men", year=2007) # OK -Assignment -^^^^^^^^^^ +Assignment and Override +^^^^^^^^^^^^^^^^^^^^^^^ -Assignments of a function typed with ``**kwargs: Unpack[Movie]`` and another +Assignments and overrides of a function typed with ``**kwargs: Unpack[Movie]`` and another callable type should pass type checking only for the scenarios described below. Source and destination contain ``**kwargs`` @@ -387,22 +387,6 @@ traditionally typed ``**kwargs`` aren't checked for keyword names. To summarize, function parameters should behave contravariantly and function return types should behave covariantly. -Method overrides -"""""""""""""""" - -The rules above also apply when checking whether a method that overrides a -method in a base class is compatible with it. As with -:ref:`@override `, the overriding method must be :term:`assignable` -to the overridden method:: - - class Base: - def method(self, **kwargs: Unpack[Animal]): ... - - class Sub(Base): - def method(self, *, name: str): ... # WRONG! Animal is not closed, - # so Base.method may be called - # with additional keyword arguments. - Unpacking a TypedDict as keyword arguments ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From cedf53f94f82a6c0782ea3bcfa889ba4f7f51ed2 Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Wed, 25 Nov 2026 22:51:56 -0500 Subject: [PATCH 15/16] update test and regenerate --- .../results/mypy/callables_kwargs.toml | 33 ++++++++------ .../results/pycroscope/callables_kwargs.toml | 42 +++++++++-------- .../results/pyrefly/callables_kwargs.toml | 35 ++++++++------- .../results/pyright/callables_kwargs.toml | 45 +++++++++++-------- conformance/results/results.html | 4 ++ conformance/results/ty/callables_kwargs.toml | 42 +++++++++-------- .../results/zuban/callables_kwargs.toml | 41 +++++++++-------- conformance/tests/callables_kwargs.py | 19 ++++++-- 8 files changed, 154 insertions(+), 107 deletions(-) diff --git a/conformance/results/mypy/callables_kwargs.toml b/conformance/results/mypy/callables_kwargs.toml index 0f84a4ca2..f5450bc22 100644 --- a/conformance/results/mypy/callables_kwargs.toml +++ b/conformance/results/mypy/callables_kwargs.toml @@ -8,6 +8,7 @@ Does not check the type of an unpacked TypedDict's extra items against the targe Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. +When `Base` is open and `Child` adds a non-required `int` key, incorrectly allows a callable taking `**kwargs: Unpack[Child]` to stand in for one taking `**kwargs: Unpack[Base]` and rejects the reverse assignment. """ output = """ callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg] @@ -41,26 +42,30 @@ errors_diff = """ Line 154: Expected 1 errors Line 174: Expected 1 errors Line 209: Expected 1 errors -Line 277: Expected 1 errors -Line 279: Expected 1 errors -Line 280: Expected 1 errors Line 282: Expected 1 errors -Line 283: Expected 1 errors Line 284: Expected 1 errors -Line 292: Expected 1 errors +Line 285: Expected 1 errors +Line 287: Expected 1 errors +Line 288: Expected 1 errors +Line 289: Expected 1 errors Line 294: Expected 1 errors Line 295: Expected 1 errors -Line 297: Expected 1 errors -Line 298: Expected 1 errors Line 299: Expected 1 errors -Line 318: Expected 1 errors -Line 319: Expected 1 errors -Line 321: Expected 1 errors -Line 322: Expected 1 errors -Line 324: Expected 1 errors -Line 325: Expected 1 errors -Line 326: Expected 1 errors +Line 301: Expected 1 errors +Line 302: Expected 1 errors +Line 304: Expected 1 errors +Line 305: Expected 1 errors +Line 306: Expected 1 errors +Line 311: Expected 1 errors +Line 312: Expected 1 errors Line 327: Expected 1 errors +Line 328: Expected 1 errors +Line 330: Expected 1 errors +Line 331: Expected 1 errors +Line 333: Expected 1 errors +Line 334: Expected 1 errors +Line 335: Expected 1 errors +Line 336: Expected 1 errors Line 27: Unexpected errors ['callables_kwargs.py:27: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] Line 210: Unexpected errors ['callables_kwargs.py:210: error: Incompatible types in assignment (expression has type "def func8(**kwargs: **TDBase) -> None", variable has type "TDProtocol10") [assignment]'] Line 228: Unexpected errors ['callables_kwargs.py:228: error: Unexpected keyword argument "extra_items" for "__init_subclass__" of "TypedDict" [call-arg]'] diff --git a/conformance/results/pycroscope/callables_kwargs.toml b/conformance/results/pycroscope/callables_kwargs.toml index b46312e50..f392a2a42 100644 --- a/conformance/results/pycroscope/callables_kwargs.toml +++ b/conformance/results/pycroscope/callables_kwargs.toml @@ -5,14 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable whose `**kwa """ conformance_automated = "Fail" errors_diff = """ -Line 277: Expected 1 errors -Line 280: Expected 1 errors -Line 283: Expected 1 errors -Line 284: Expected 1 errors -Line 292: Expected 1 errors -Line 295: Expected 1 errors -Line 298: Expected 1 errors +Line 282: Expected 1 errors +Line 285: Expected 1 errors +Line 288: Expected 1 errors +Line 289: Expected 1 errors Line 299: Expected 1 errors +Line 302: Expected 1 errors +Line 305: Expected 1 errors +Line 306: Expected 1 errors """ output = """ ./callables_kwargs.py:55:4: In call to callables_kwargs.func1: Missing required argument 'v1' [incompatible_call] @@ -31,16 +31,20 @@ output = """ ./callables_kwargs.py:154:0: Incompatible assignment: expected callables_kwargs.TDProtocol6, got function 'callables_kwargs.func7' [incompatible_assignment] ./callables_kwargs.py:174:4: Value of method incompatible with base class callables_kwargs.BaseUnpacked [incompatible_override] ./callables_kwargs.py:209:0: Incompatible assignment: expected callables_kwargs.TDProtocol9, got function 'callables_kwargs.func9' [incompatible_assignment] -./callables_kwargs.py:279:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:282:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:294:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:297:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:318:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:319:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:321:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:322:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] -./callables_kwargs.py:324:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:325:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] -./callables_kwargs.py:326:4: Incompatible argument type for label: expected str but got int [incompatible_argument] -./callables_kwargs.py:327:4: Incompatible argument type for label: expected str but got int [incompatible_argument] +./callables_kwargs.py:284:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:287:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:294:4: Incompatible argument type for kwargs: expected dict[str, int] but got [incompatible_argument] +./callables_kwargs.py:295:4: Incompatible argument type for kwargs: expected dict[str, int] but got [incompatible_argument] +./callables_kwargs.py:301:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:304:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:311:4: Incompatible argument type for kwargs: expected dict[str, int] but got [incompatible_argument] +./callables_kwargs.py:312:4: Incompatible argument type for kwargs: expected dict[str, int] but got [incompatible_argument] +./callables_kwargs.py:327:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:328:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:330:4: In call to callables_kwargs.takes_name: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:331:4: Incompatible argument type for kwargs: expected dict[str, str] but got [incompatible_argument] +./callables_kwargs.py:333:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:334:4: In call to callables_kwargs.takes_closed: **kwargs provided but not used [incompatible_call] +./callables_kwargs.py:335:4: Incompatible argument type for label: expected str but got int [incompatible_argument] +./callables_kwargs.py:336:4: Incompatible argument type for label: expected str but got int [incompatible_argument] """ diff --git a/conformance/results/pyrefly/callables_kwargs.toml b/conformance/results/pyrefly/callables_kwargs.toml index cb1afbfb5..38319a681 100644 --- a/conformance/results/pyrefly/callables_kwargs.toml +++ b/conformance/results/pyrefly/callables_kwargs.toml @@ -3,22 +3,27 @@ notes = """ Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not treat an open TypedDict as having extra items of type `object` when checking against the target callable's `**kwargs` annotation. +Incorrectly allows a callable taking `**kwargs: Unpack[Child]` to stand in for one taking `**kwargs: Unpack[Base]` when `Base` is open and `Child` adds a non-required `int` key. """ conformance_automated = "Fail" errors_diff = """ Line 209: Expected 1 errors -Line 277: Expected 1 errors -Line 279: Expected 1 errors -Line 280: Expected 1 errors Line 282: Expected 1 errors -Line 283: Expected 1 errors Line 284: Expected 1 errors -Line 292: Expected 1 errors +Line 285: Expected 1 errors +Line 287: Expected 1 errors +Line 288: Expected 1 errors +Line 289: Expected 1 errors Line 294: Expected 1 errors Line 295: Expected 1 errors -Line 297: Expected 1 errors -Line 298: Expected 1 errors Line 299: Expected 1 errors +Line 301: Expected 1 errors +Line 302: Expected 1 errors +Line 304: Expected 1 errors +Line 305: Expected 1 errors +Line 306: Expected 1 errors +Line 311: Expected 1 errors +Line 312: Expected 1 errors """ output = """ ERROR callables_kwargs.py:55:10-12: Missing argument `v1` in function `func1` [missing-argument] @@ -39,12 +44,12 @@ ERROR callables_kwargs.py:131:20-41: TypedDict key 'v1' in **kwargs overlaps wit ERROR callables_kwargs.py:142:21-30: `Unpack` in **kwargs annotation must be used only with a `TypedDict` [invalid-annotation] ERROR callables_kwargs.py:154:19-24: `(*, v1: int, v3: str, v2: str = '') -> None` is not assignable to `TDProtocol6` [bad-assignment] ERROR callables_kwargs.py:174:9-15: Class member `SubNoKwargs.method` overrides parent class `BaseUnpacked` in an inconsistent manner [bad-override] -ERROR callables_kwargs.py:318:16-23: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] -ERROR callables_kwargs.py:319:27-34: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] -ERROR callables_kwargs.py:321:16-24: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] -ERROR callables_kwargs.py:322:27-35: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] -ERROR callables_kwargs.py:324:18-25: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] -ERROR callables_kwargs.py:325:18-26: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] -ERROR callables_kwargs.py:326:37-44: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] -ERROR callables_kwargs.py:327:37-45: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:327:16-23: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] +ERROR callables_kwargs.py:328:27-34: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:330:16-24: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_name` [unexpected-keyword] +ERROR callables_kwargs.py:331:27-35: Extra items of type `int` are not assignable to parameter `kwargs` with type `str` in function `takes_name_str_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:333:18-25: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] +ERROR callables_kwargs.py:334:18-26: `TDExtraItems` may contain extra items of type `int`, which cannot be unpacked into a callable that accepts no extra keyword arguments in function `takes_closed` [unexpected-keyword] +ERROR callables_kwargs.py:335:37-44: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] +ERROR callables_kwargs.py:336:37-45: Extra items of type `int` are not assignable to parameter `label` with type `str` in function `takes_optional_label_int_kwargs` [bad-argument-type] """ diff --git a/conformance/results/pyright/callables_kwargs.toml b/conformance/results/pyright/callables_kwargs.toml index ff32ce808..916a7c0c6 100644 --- a/conformance/results/pyright/callables_kwargs.toml +++ b/conformance/results/pyright/callables_kwargs.toml @@ -5,6 +5,7 @@ Does not reject unpacking an open TypedDict in a call to a callable whose `**kwa Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable that has no `**kwargs`. Does not reject unpacking a TypedDict that sets `extra_items` in a call to a callable whose `**kwargs` is typed with a closed TypedDict. Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters. +Incorrectly rejects assigning a callable taking `**kwargs: Unpack[Base]` to one taking `**kwargs: Unpack[Child]` when `Base` is open and `Child` adds a non-required `int` key. """ output = """ callables_kwargs.py:37:5 - error: Could not access item in TypedDict @@ -51,34 +52,42 @@ callables_kwargs.py:210:21 - error: Type "(**kwargs: **TDBase) -> None" is not a   Type "(**kwargs: **TDBase) -> None" is not assignable to type "(**kwargs: **TDChild) -> None"     Parameter 1: type "int" is incompatible with type "*TDBase"       "int" is not assignable to "*TDBase" (reportAssignmentType) -callables_kwargs.py:279:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:284:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:282:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:287:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:294:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:294:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "int" in function "takes_extra_items_int" +  "object" is not assignable to "int" (reportArgumentType) +callables_kwargs.py:295:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "int" in function "takes_extra_items_int" +  "object" is not assignable to "int" (reportArgumentType) +callables_kwargs.py:301:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:297:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:304:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "object" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:319:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:311:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "int" in function "takes_extra_items_int" +  "object" is not assignable to "int" (reportArgumentType) +callables_kwargs.py:312:29 - error: Argument of type "object" cannot be assigned to parameter "kwargs" of type "int" in function "takes_extra_items_int" +  "object" is not assignable to "int" (reportArgumentType) +callables_kwargs.py:328:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) -callables_kwargs.py:322:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs" +callables_kwargs.py:331:29 - error: Argument of type "int" cannot be assigned to parameter "kwargs" of type "str" in function "takes_name_str_kwargs"   "int" is not assignable to "str" (reportArgumentType) """ conformance_automated = "Fail" errors_diff = """ -Line 277: Expected 1 errors -Line 280: Expected 1 errors -Line 283: Expected 1 errors -Line 284: Expected 1 errors -Line 292: Expected 1 errors -Line 295: Expected 1 errors -Line 298: Expected 1 errors +Line 282: Expected 1 errors +Line 285: Expected 1 errors +Line 288: Expected 1 errors +Line 289: Expected 1 errors Line 299: Expected 1 errors -Line 318: Expected 1 errors -Line 321: Expected 1 errors -Line 324: Expected 1 errors -Line 325: Expected 1 errors -Line 326: Expected 1 errors +Line 302: Expected 1 errors +Line 305: Expected 1 errors +Line 306: Expected 1 errors Line 327: Expected 1 errors +Line 330: Expected 1 errors +Line 333: Expected 1 errors +Line 334: Expected 1 errors +Line 335: Expected 1 errors +Line 336: Expected 1 errors Line 210: Unexpected errors ['callables_kwargs.py:210:21 - error: Type "(**kwargs: **TDBase) -> None" is not assignable to declared type "TDProtocol10"'] """ diff --git a/conformance/results/results.html b/conformance/results/results.html index ac25d7aa3..593d7d0f7 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -1437,6 +1437,7 @@

      Python Type System Conformance Test Results

    • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
    • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • +
    • When Base is open and Child adds a non-required int key, incorrectly allows a callable taking **kwargs: Unpack[Child] to stand in for one taking **kwargs: Unpack[Base] and rejects the reverse assignment.
    @@ -1452,6 +1453,7 @@

    Python Type System Conformance Test Results

  • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
  • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
  • Does not treat an open TypedDict as having extra items of type object when checking against the target callable's **kwargs annotation.
  • +
  • Incorrectly allows a callable taking **kwargs: Unpack[Child] to stand in for one taking **kwargs: Unpack[Base] when Base is open and Child adds a non-required int key.
  • @@ -1462,6 +1464,7 @@

    Python Type System Conformance Test Results

  • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable that has no **kwargs.
  • Does not reject unpacking a TypedDict that sets extra_items in a call to a callable whose **kwargs is typed with a closed TypedDict.
  • Does not check the type of an unpacked TypedDict's extra items against the target callable's named keyword parameters.
  • +
  • Incorrectly rejects assigning a callable taking **kwargs: Unpack[Base] to one taking **kwargs: Unpack[Child] when Base is open and Child adds a non-required int key.
  • @@ -1476,6 +1479,7 @@

    Python Type System Conformance Test Results

    • Does not reject unpacking an open TypedDict in a call to a callable that has no **kwargs.
    • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a closed TypedDict.
    • +
    • Does not reject unpacking an open TypedDict in a call to a callable whose **kwargs is typed with a TypedDict whose extra_items type is narrower than object.
    diff --git a/conformance/results/ty/callables_kwargs.toml b/conformance/results/ty/callables_kwargs.toml index 1b5cf53b9..303bf2d8f 100644 --- a/conformance/results/ty/callables_kwargs.toml +++ b/conformance/results/ty/callables_kwargs.toml @@ -5,14 +5,14 @@ Does not reject unpacking an open TypedDict in a call to a callable that has no Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. """ errors_diff = """ -Line 277: Expected 1 errors -Line 280: Expected 1 errors -Line 283: Expected 1 errors -Line 284: Expected 1 errors -Line 292: Expected 1 errors -Line 295: Expected 1 errors -Line 298: Expected 1 errors +Line 282: Expected 1 errors +Line 285: Expected 1 errors +Line 288: Expected 1 errors +Line 289: Expected 1 errors Line 299: Expected 1 errors +Line 302: Expected 1 errors +Line 305: Expected 1 errors +Line 306: Expected 1 errors """ output = """ callables_kwargs.py:55:5: error[missing-argument] No arguments provided for required parameters `v1`, `v3` of function `func1` @@ -32,16 +32,20 @@ callables_kwargs.py:142:21: error[invalid-type-form] Unpacked value for `**kwarg callables_kwargs.py:154:19: error[invalid-assignment] Object of type `def func7(*, v1: int, v3: str, v2: str = "") -> None` is not assignable to `TDProtocol6` callables_kwargs.py:174:9: error[incompatible-method-override] Invalid override of method `method`: Definition is incompatible with `BaseUnpacked.method` callables_kwargs.py:209:20: error[invalid-assignment] Object of type `def func9(*, x: int, y: int = ..., **kwargs: object) -> None` is not assignable to `TDProtocol9` -callables_kwargs.py:279:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:282:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:294:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:297:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` -callables_kwargs.py:318:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:319:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:321:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` -callables_kwargs.py:322:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:324:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` -callables_kwargs.py:325:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` -callables_kwargs.py:326:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` -callables_kwargs.py:327:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:284:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:287:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:294:27: error[invalid-argument-type] Argument to function `takes_extra_items_int` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `int` +callables_kwargs.py:295:27: error[invalid-argument-type] Argument to function `takes_extra_items_int` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `int` +callables_kwargs.py:301:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:304:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `str` +callables_kwargs.py:311:27: error[invalid-argument-type] Argument to function `takes_extra_items_int` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `int` +callables_kwargs.py:312:27: error[invalid-argument-type] Argument to function `takes_extra_items_int` is incorrect: Possible extra items in unpacked open `TypedDict` have type `object`, expected `int` +callables_kwargs.py:327:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:328:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:330:16: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_name` +callables_kwargs.py:331:27: error[invalid-argument-type] Argument to function `takes_name_str_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:333:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:334:18: error[unknown-argument] Unpacked argument may contain keyword arguments that do not match any known parameter of function `takes_closed` +callables_kwargs.py:335:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` +callables_kwargs.py:336:37: error[invalid-argument-type] Argument to function `takes_optional_label_int_kwargs` is incorrect: Expected `str`, found `int` """ diff --git a/conformance/results/zuban/callables_kwargs.toml b/conformance/results/zuban/callables_kwargs.toml index 6564f4ccf..59da37f90 100644 --- a/conformance/results/zuban/callables_kwargs.toml +++ b/conformance/results/zuban/callables_kwargs.toml @@ -2,17 +2,22 @@ conformant = "Partial" notes = """ Does not reject unpacking an open TypedDict in a call to a callable that has no `**kwargs`. Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a closed TypedDict. +Does not reject unpacking an open TypedDict in a call to a callable whose `**kwargs` is typed with a TypedDict whose `extra_items` type is narrower than `object`. """ conformance_automated = "Fail" errors_diff = """ -Line 277: Expected 1 errors -Line 280: Expected 1 errors -Line 283: Expected 1 errors -Line 284: Expected 1 errors -Line 292: Expected 1 errors +Line 282: Expected 1 errors +Line 285: Expected 1 errors +Line 288: Expected 1 errors +Line 289: Expected 1 errors +Line 294: Expected 1 errors Line 295: Expected 1 errors -Line 298: Expected 1 errors Line 299: Expected 1 errors +Line 302: Expected 1 errors +Line 305: Expected 1 errors +Line 306: Expected 1 errors +Line 311: Expected 1 errors +Line 312: Expected 1 errors """ output = """ callables_kwargs.py:55: error: Missing named argument "v1" for "func1" [call-arg] @@ -41,16 +46,16 @@ callables_kwargs.py:174: note: def method(self, **kwargs: Unpack[TDPers callables_kwargs.py:174: note: Subclass: callables_kwargs.py:174: note: def method(self, *, name: str, age: int, extra: bool = ...) -> None callables_kwargs.py:209: error: Incompatible types in assignment (expression has type "def func9(**kwargs: Unpack[TDChild]) -> None", variable has type "TDProtocol9") [assignment] -callables_kwargs.py:279: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] -callables_kwargs.py:282: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] -callables_kwargs.py:294: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] -callables_kwargs.py:297: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] -callables_kwargs.py:318: error: Too many arguments for "takes_name" [call-arg] -callables_kwargs.py:319: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:321: error: Too many arguments for "takes_name" [call-arg] -callables_kwargs.py:322: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:324: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] -callables_kwargs.py:325: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] -callables_kwargs.py:326: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] -callables_kwargs.py:327: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:284: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] +callables_kwargs.py:287: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenImplicit"; expected "str" [arg-type] +callables_kwargs.py:301: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] +callables_kwargs.py:304: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDOpenExplicit"; expected "str" [arg-type] +callables_kwargs.py:327: error: Too many arguments for "takes_name" [call-arg] +callables_kwargs.py:328: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:330: error: Too many arguments for "takes_name" [call-arg] +callables_kwargs.py:331: error: Argument 1 to "takes_name_str_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:333: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:334: error: Argument 1 to "takes_closed" has incompatible type "**TDExtraItems"; expected "Never" [arg-type] +callables_kwargs.py:335: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] +callables_kwargs.py:336: error: Argument 1 to "takes_optional_label_int_kwargs" has incompatible type "**TDExtraItems"; expected "str" [arg-type] """ diff --git a/conformance/tests/callables_kwargs.py b/conformance/tests/callables_kwargs.py index 6f7fbd742..e4b920e4d 100644 --- a/conformance/tests/callables_kwargs.py +++ b/conformance/tests/callables_kwargs.py @@ -114,7 +114,7 @@ def __call__(self, **kwargs: Unpack[TD4]) -> None: ... -# Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#assignment +# Specification: https://typing.readthedocs.io/en/latest/spec/callables.html#assignment-and-override v1: TDProtocol1 = func1 # OK v2: TDProtocol2 = func1 # OK @@ -143,8 +143,8 @@ def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a TypedDict ... # > The situation where the destination callable contains **kwargs: Unpack[TypedDict] and -# > the source callable doesn’t contain **kwargs should be disallowed, if the TypedDict is not :term:`closed`. -# > This is because we cannot be sure that additional keyword arguments are not being passed in when an instance of a subclass +# > the source callable doesn’t contain **kwargs should be disallowed if the TypedDict is not :term:`closed`. +# > This is because additional keyword arguments could be 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: @@ -270,8 +270,13 @@ def takes_extra_items_object(**kwargs: Unpack[TDExtraItemsObject]) -> None: ... +# Equivalent to `def takes_extra_items_int(*, name: str, **kwargs: int)`. +def takes_extra_items_int(**kwargs: Unpack[TDExtraItems]) -> None: + ... + + # > It is only safe to unpack a non-:term:`closed` TypedDict in a function call if that function has -# > ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. +# > ``**kwargs`` in its signature, and all :term:`extra items` are assignable to the type of ``**kwargs``. def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> None: takes_name(**value) # E: a subtype may contain unknown keys @@ -286,6 +291,8 @@ def open_implicit(value: TDOpenImplicit, **kwargs: Unpack[TDOpenImplicit]) -> No takes_name_object_kwargs(**kwargs) takes_extra_items_object(**value) takes_extra_items_object(**kwargs) + takes_extra_items_int(**value) # E: extra items type is not compatible + takes_extra_items_int(**kwargs) # E: extra items type is not compatible def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> None: @@ -301,6 +308,8 @@ def open_explicit(value:TDOpenExplicit, **kwargs: Unpack[TDOpenExplicit]) -> Non takes_name_object_kwargs(**kwargs) takes_extra_items_object(**value) takes_extra_items_object(**kwargs) + takes_extra_items_int(**value) # E: extra items type is not compatible + takes_extra_items_int(**kwargs) # E: extra items type is not compatible def kwargs_closed(value: TDClosed, **kwargs: Unpack[TDClosed]) -> None: @@ -327,6 +336,8 @@ def kwargs_extra_items(value: TDExtraItems, **kwargs: Unpack[TDExtraItems]) -> N takes_optional_label_int_kwargs(**kwargs) # E: extra items type is not compatible w/ `label` param takes_extra_items_object(**value) takes_extra_items_object(**kwargs) + takes_extra_items_int(**value) + takes_extra_items_int(**kwargs) def kwargs_extra_items_never(value: TDExtraItemsNever, **kwargs: Unpack[TDExtraItemsNever]) -> None: From ff7b65e66671d75baa1fd7cdcea0110e67015d0f Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Wed, 25 Nov 2026 23:12:33 -0500 Subject: [PATCH 16/16] make small edits --- docs/spec/callables.rst | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index 66dc600a1..1a1af3d77 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -266,7 +266,7 @@ assignable:: This also applies when the source function's ``TypedDict`` only adds :term:`non-required` keys. Because an :term:`open` ``TypedDict`` is -treated as having read-only :term:`extra items` of type ``object`` for the +treated as having read-only (thus covariant) :term:`extra items` of type ``object`` for the purposes of :ref:`assignability `, a callable whose ``**kwargs`` is typed with an open ``TypedDict`` may be called with additional keyword arguments of any type:: @@ -325,9 +325,9 @@ only:: The reverse situation where the destination callable contains ``**kwargs: Unpack[TypedDict]`` and the source callable doesn't contain -``**kwargs`` should be disallowed, if the TypedDict is not :term:`closed`. 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 +``**kwargs`` should be disallowed if the TypedDict is not :term:`closed`. This is because +additional keyword arguments could be 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 dest(**kwargs: Unpack[Animal]): ... @@ -435,24 +435,28 @@ The calls to ``bar`` and ``spam`` will fail because an unexpected keyword argument will be passed to the ``takes_name`` function. Therefore, it is only safe to unpack a non-:term:`closed` TypedDict in a function call -if that function has ``**kwargs`` in its signature, and any :term:`extra items` are assignable to the type of ``**kwargs``. -For these rules, :term:`open` TypedDicts are treated as having :term:`extra items` of -type ``object``. - -- If the callee has non-unpacked ``**kwargs``, checkers should error if the TypedDict's - :term:`extra items` are not assignable to the type of ``**kwargs``. -- If the callee has unpacked ``**kwargs`` (``**kwargs: Unpack[TD]``), checkers should - error if the TypedDict's :term:`extra items` are not assignable to ``TD``'s extra +if that function has ``**kwargs`` in its signature, and all :term:`extra items` are +assignable to the type of ``**kwargs``. +For these rules, :term:`open` TypedDicts are treated as having read-only (thus +covariant) :term:`extra items` of type ``object``. + +- If the callee has a non-unpacked ``**kwargs`` type, checkers should error if the + ``TypedDict``'s :term:`extra items` are not assignable to the type of ``**kwargs``. +- If the callee has an unpacked ``**kwargs`` type (``**kwargs: Unpack[TD]``), checkers should + error if the ``TypedDict``'s :term:`extra items` are not assignable to ``TD``'s extra items, treating a :term:`closed` ``TD`` as accepting no extra items. -- If the callee does not have ``**kwargs``, checkers should error if the TypedDict is - :term:`open`, and should error if the TypedDict declares non-``Never`` +- If the callee does not have ``**kwargs``, checkers should error if the ``TypedDict`` is + :term:`open`, and should error if the ``TypedDict`` declares non-``Never`` :term:`extra items`. -Additionally, the type of :term:`extra items` must be assignable to any keyword parameters the function call does not provide. +Additionally, the type of :term:`extra items` must be assignable to any keyword parameters +the function call does not provide. In cases similar to the ``bar`` function above the problem could be worked -around by marking ``Animal`` with ``closed=True``, or by explicitly dereferencing desired -fields and using them as arguments to perform the function call:: +around by marking ``Animal`` with ``closed=True`` (which also prevents subclasses +such as ``Dog`` from adding items like ``breed``), or by explicitly dereferencing +desired fields and using them as arguments to perform the function call. Unlike +closing ``Animal``, this still allows a ``Dog`` to be passed to ``bar``:: def bar(**kwargs: Unpack[Animal]): name = kwargs["name"]