[Python-checkins] cpython (3.5): Hopefully clarify the difference between Optional[t] and an optional argument.

guido.van.rossum python-checkins at python.org
Wed Feb 10 12:50:13 EST 2016


https://hg.python.org/cpython/rev/3940f38b0593
changeset:   100219:3940f38b0593
branch:      3.5
parent:      100215:1c2de3b0a474
user:        Guido van Rossum <guido at python.org>
date:        Wed Feb 10 09:48:58 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