[Python-checkins] peps: Give an explicit example for how to annotate *args, **kwds.
guido.van.rossum
python-checkins at python.org
Tue Mar 22 17:54:46 EDT 2016
https://hg.python.org/peps/rev/42238ed029c6
changeset: 6267:42238ed029c6
user: Guido van Rossum <guido at python.org>
date: Tue Mar 22 14:54:38 2016 -0700
summary:
Give an explicit example for how to annotate *args, **kwds.
files:
pep-0484.txt | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/pep-0484.txt b/pep-0484.txt
--- a/pep-0484.txt
+++ b/pep-0484.txt
@@ -885,8 +885,24 @@
``"".join(reversed(sys.platform)) == "xunil"``.
-Default argument values
------------------------
+Arbitrary argument lists and default argument values
+----------------------------------------------------
+
+Arbitrary agrument lists can as well be type annotated,
+so that the definition::
+
+ def foo(*args: str, **kwds: int): ...
+
+is acceptable and it means that, e.g., all of the following
+represent function calls with valid types of arguments::
+
+ foo('a', 'b', 'c')
+ foo(x=1, y=2)
+ foo('', z=0)
+
+In the body of function ``foo``, the type of variable ``args`` is
+deduced as ``Tuple[str, ...]`` and the type of variable ``kwds``
+is ``Dict[str, int]``.
In stubs it may be useful to declare an argument as having a default
without specifying the actual default value. For example::
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list