Skip to content

Commit 8a2afd2

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 <ja.py@farowl.co.uk>
1 parent 43d8860 commit 8a2afd2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Doc/reference/expressions.rst

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

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

0 commit comments

Comments
 (0)