summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-09-22 18:17:30 (GMT)
committerGitHub <noreply@github.com>2022-09-22 18:17:30 (GMT)
commit8a2afd295b77cebe940b9772d55243a6f7186ed9 (patch)
tree4321a50159b0d79309c61cc4c35faa68cd3e406f /Doc/reference
parent43d8860aa247148b95e654775acb10b2f7e7b571 (diff)
downloadcpython-8a2afd295b77cebe940b9772d55243a6f7186ed9.zip
cpython-8a2afd295b77cebe940b9772d55243a6f7186ed9.tar.gz
cpython-8a2afd295b77cebe940b9772d55243a6f7186ed9.tar.bz2
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 9d432b4a181cd42017699de4354e7b36c5b87d88) Co-authored-by: Jeff Allen <ja.py@farowl.co.uk>
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/expressions.rst14
1 files changed, 12 insertions, 2 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index b8c8d5f..0a9e714 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -1049,10 +1049,20 @@ used in the same call, so in practice this confusion does not arise.
If the syntax ``**expression`` appears in the function call, ``expression`` must
evaluate to a :term:`mapping`, the contents of which are treated as
-additional keyword arguments. If a keyword is already present
-(as an explicit keyword argument, or from another unpacking),
+additional keyword arguments. If a parameter matching a key has already been
+given a value (by an explicit keyword argument, or from another unpacking),
a :exc:`TypeError` exception is raised.
+When ``**expression`` is used, each key in this mapping must be
+a string.
+Each value from the mapping is assigned to the first formal parameter
+eligible for keyword assignment whose name is equal to the key.
+A key need not be a Python identifier (e.g. ``"max-temp °F"`` is acceptable,
+although it will not match any formal parameter that could be declared).
+If there is no match to a formal parameter
+the key-value pair is collected by the ``**`` parameter, if there is one,
+or if there is not, a :exc:`TypeError` exception is raised.
+
Formal parameters using the syntax ``*identifier`` or ``**identifier`` cannot be
used as positional argument slots or as keyword argument names.