Skip to content

Commit 336c945

Browse files
scopilevkivskyi
authored andcommittedAug 5, 2018
bpo-34336: Don't promote possibility to leave out typing.Optional (python#8677)
1 parent 87e59ac commit 336c945

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

‎Doc/library/typing.rst

+12-4
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,18 @@ The module defines the following classes, functions and decorators:
990990

991991
Note that this is not the same concept as an optional argument,
992992
which is one that has a default. An optional argument with a
993-
default needn't use the ``Optional`` qualifier on its type
994-
annotation (although it is inferred if the default is ``None``).
995-
A mandatory argument may still have an ``Optional`` type if an
996-
explicit value of ``None`` is allowed.
993+
default does not require the ``Optional`` qualifier on its type
994+
annotation just because it is optional. For example::
995+
996+
def foo(arg: int = 0) -> None:
997+
...
998+
999+
On the other hand, if an explicit value of ``None`` is allowed, the
1000+
use of ``Optional`` is appropriate, whether the argument is optional
1001+
or not. For example::
1002+
1003+
def foo(arg: Optional[int] = None) -> None:
1004+
...
9971005

9981006
.. data:: Tuple
9991007

0 commit comments

Comments
 (0)
Please sign in to comment.