[Python-checkins] bpo-34336: Don't promote possibility to leave out typing.Optional (GH-8677)
Miss Islington (bot)
webhook-mailer at python.org
Sun Aug 5 13:22:50 EDT 2018
https://github.com/python/cpython/commit/02c4eae35cd24ab71c12b5e61ec22e993ac4839b
commit: 02c4eae35cd24ab71c12b5e61ec22e993ac4839b
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-08-05T10:22:47-07:00
summary:
bpo-34336: Don't promote possibility to leave out typing.Optional (GH-8677)
(cherry picked from commit 336c945858055059a65134d4c501a85037d70d99)
Co-authored-by: Ville Skyttä <ville.skytta at iki.fi>
files:
M Doc/library/typing.rst
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index bd6f3a95fe62..91d8a5fcf788 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -992,10 +992,18 @@ The module defines the following classes, functions and decorators:
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.
+ default does not require the ``Optional`` qualifier on its type
+ annotation just because it is optional. For example::
+
+ def foo(arg: int = 0) -> None:
+ ...
+
+ On the other hand, if an explicit value of ``None`` is allowed, the
+ use of ``Optional`` is appropriate, whether the argument is optional
+ or not. For example::
+
+ def foo(arg: Optional[int] = None) -> None:
+ ...
.. data:: Tuple
More information about the Python-checkins
mailing list