Skip to content

Commit 9eb1e6c

Browse files
gh-96397: Document that keywords in calls need not be identifiers (GH-96393)
This represents the official SC stance, see https://github.com/python/steering-council/issues/142GH-issuecomment-1252172695 (cherry picked from commit 9d432b4) Co-authored-by: Jeff Allen <[email protected]>
1 parent 6642d8a commit 9eb1e6c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Doc/reference/expressions.rst

+12-2
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,20 @@ used in the same call, so in practice this confusion does not often arise.
10541054
10551055
If the syntax ``**expression`` appears in the function call, ``expression`` must
10561056
evaluate to a :term:`mapping`, the contents of which are treated as
1057-
additional keyword arguments. If a keyword is already present
1058-
(as an explicit keyword argument, or from another unpacking),
1057+
additional keyword arguments. If a parameter matching a key has already been
1058+
given a value (by an explicit keyword argument, or from another unpacking),
10591059
a :exc:`TypeError` exception is raised.
10601060

1061+
When ``**expression`` is used, each key in this mapping must be
1062+
a string.
1063+
Each value from the mapping is assigned to the first formal parameter
1064+
eligible for keyword assignment whose name is equal to the key.
1065+
A key need not be a Python identifier (e.g. ``"max-temp °F"`` is acceptable,
1066+
although it will not match any formal parameter that could be declared).
1067+
If there is no match to a formal parameter
1068+
the key-value pair is collected by the ``**`` parameter, if there is one,
1069+
or if there is not, a :exc:`TypeError` exception is raised.
1070+
10611071
Formal parameters using the syntax ``*identifier`` or ``**identifier`` cannot be
10621072
used as positional argument slots or as keyword argument names.
10631073

0 commit comments

Comments
 (0)