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.
This commit is contained in:
Jelle Zijlstra 2018-07-09 21:22:44 -07:00 committed by Guido van Rossum
parent 8a3ed368bb
commit 0630155b47
1 changed files with 5 additions and 3 deletions

View File

@ -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
-------------------------------------