[Python-checkins] cpython: Hopefully clarify the difference between Optional[t] and an optional argument.
guido.van.rossum
python-checkins at python.org
Wed Feb 10 12:47:30 EST 2016
https://hg.python.org/cpython/rev/d9f922d57501
changeset: 100218:d9f922d57501
parent: 100216:c711c36cf988
user: Guido van Rossum <guido at python.org>
date: Wed Feb 10 09:46:56 2016 -0800
summary:
Hopefully clarify the difference between Optional[t] and an optional argument.
files:
Doc/library/typing.rst | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -286,6 +286,13 @@
``Optional[X]`` is equivalent to ``Union[X, type(None)]``.
+ Note that this is not the same concept as an optional argument,
+ which is one that has a default. An optional argument with a
+ default needn't use the ``Optional`` qualifier on its type
+ annotation (although it is inferred if the default is ``None``).
+ A mandatory argument may still have an ``Optional`` type if an
+ explicit value of ``None`` is allowed.
+
.. class:: Tuple
Tuple type; ``Tuple[X, Y]`` is the is the type of a tuple of two items
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list