Skip to content

Commit ceef46e

Browse files
committed
add comments and notes
1 parent 45500fd commit ceef46e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

conformance/results/mypy/callables_kwargs.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
conformant = "Partial"
2+
notes="""
3+
Allows callable without kwargs to be assigned to callable with unpacked kwargs
4+
Allows unpacked kwargs to be used when invoking function without kwargs
5+
"""
26
output = """
37
callables_kwargs.py:22: note: "func1" defined here
48
callables_kwargs.py:46: error: Missing named argument "v1" for "func1" [call-arg]

conformance/results/pyright/callables_kwargs.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
conformant = "Partial"
2+
notes="""
3+
Allows callable without kwargs to be assigned to callable with unpacked kwargs
4+
Allows unpacked kwargs to be used when invoking function without kwargs
5+
"""
26
output = """
37
callables_kwargs.py:28:5 - error: Could not access item in TypedDict
48
  "v2" is not a required key in "TD2", so access may result in runtime exception (reportTypedDictNotRequiredAccess)

conformance/tests/callables_kwargs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,25 @@ def func5(v1: int, **kwargs: Unpack[TD2]) -> None: # E: parameter v1 overlaps w
122122
def func6(**kwargs: Unpack[T]) -> None: # E: unpacked value must be a TypedDict, not a TypeVar bound to TypedDict.
123123
...
124124

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

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

129133

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

136+
# > Kwargs hinted with an unpacked TypedDict can only be passed to another function if the function
137+
# > to which unpacked kwargs are being passed to has **kwargs in its signature as well,
138+
# > because then additional keywords would not cause errors at runtime during function invocation.
139+
# > Otherwise, the type checker should generate an error.
132140

133141
def func8(**kwargs) -> None:
134142
...
135143

136144
def func9(**kwargs: Unpack[TD2]) -> None:
137-
# Kwargs hinted with an unpacked TypedDict can only be passed to another function that has **kwargs in its signature.
138145
func7(**kwargs) # E
139146
func8(**kwargs) # OK

0 commit comments

Comments
 (0)