From 0630155b47c27f25e66267d247f0205aa953f113 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 9 Jul 2018 21:22:44 -0700 Subject: [PATCH] PEP 484: Do not require type checkers to treat a None default specially (#689) Following discussion in python/typing#275, there is a consensus that it is better to require optional types to be made explicit. This PR changes the wording of PEP 484 to encourage type checkers to treat a None default as implicitly making an argument Optional. --- pep-0484.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt index 66a273771fa..b5a0550494b 100644 --- a/pep-0484.txt +++ b/pep-0484.txt @@ -984,15 +984,17 @@ for example, the above is equivalent to:: def handle_employee(e: Optional[Employee]) -> None: ... -An optional type is also automatically assumed when the default value is -``None``, for example:: +A past version of this PEP allowed type checkers to assume an optional +type when the default value is ``None``, as in this code:: def handle_employee(e: Employee = None): ... -This is equivalent to:: +This would have been treated as equivalent to:: def handle_employee(e: Optional[Employee] = None) -> None: ... +This is no longer the recommended behavior. Type checkers should move +towards requiring the optional type to be made explicit. Support for singleton types in unions -------------------------------------