Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pep-0484.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe I was too wishy-washy. Pondering this again I think the language in PEP 484 should acknowledge that PEP 484 used to automatically infer Optional[] based on an = None default, and that type-checkers historically did it that way, but that we changed our mind and that in the future the PEP will mandate that this not be done. What type checkers currently do is then merely dependent on where the type checker is in its migration to the future behavior.

Does that make sense?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra Any response to that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about this one, will get back to it soon.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this new wording?


Support for singleton types in unions
-------------------------------------
Expand Down