Skip to content

Commit 0630155

Browse files
JelleZijlstragvanrossum
authored andcommitted
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.
1 parent 8a3ed36 commit 0630155

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: pep-0484.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -984,15 +984,17 @@ for example, the above is equivalent to::
984984

985985
def handle_employee(e: Optional[Employee]) -> None: ...
986986

987-
An optional type is also automatically assumed when the default value is
988-
``None``, for example::
987+
A past version of this PEP allowed type checkers to assume an optional
988+
type when the default value is ``None``, as in this code::
989989

990990
def handle_employee(e: Employee = None): ...
991991

992-
This is equivalent to::
992+
This would have been treated as equivalent to::
993993

994994
def handle_employee(e: Optional[Employee] = None) -> None: ...
995995

996+
This is no longer the recommended behavior. Type checkers should move
997+
towards requiring the optional type to be made explicit.
996998

997999
Support for singleton types in unions
9981000
-------------------------------------

0 commit comments

Comments
 (0)