From 15740d3b279df566377c38ff4e203fe0ff9577cf Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 30 Jun 2018 22:57:01 -0700 Subject: [PATCH 1/2] Do not require type checkers to treat a None default specially 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 allow, but not require, type checkers to treat a None default as implicitly making an argument Optional. --- pep-0484.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt index 39d72b077cd..19c51593718 100644 --- a/pep-0484.txt +++ b/pep-0484.txt @@ -984,15 +984,16 @@ 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:: +Type checkers may also automatically assume an optional type when the +default value is ``None``, for example:: def handle_employee(e: Employee = None): ... -This is equivalent to:: +This may be treated as equivalent to:: def handle_employee(e: Optional[Employee] = None) -> None: ... +Type checkers may also require the optional type to be made explicit. Support for singleton types in unions ------------------------------------- From 849f9b092f2077be44a671313f5c8e7965ef1d39 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 9 Jul 2018 19:07:43 -0700 Subject: [PATCH 2/2] Be more explicit that we're moving away from implicit optional --- pep-0484.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pep-0484.txt b/pep-0484.txt index 19c51593718..97de11cc4e9 100644 --- a/pep-0484.txt +++ b/pep-0484.txt @@ -984,16 +984,17 @@ for example, the above is equivalent to:: def handle_employee(e: Optional[Employee]) -> None: ... -Type checkers may also automatically assume an optional type 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 may be treated as equivalent to:: +This would have been treated as equivalent to:: def handle_employee(e: Optional[Employee] = None) -> None: ... -Type checkers may also require the optional type to be made explicit. +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 -------------------------------------