8000 PEP 484: Do not require type checkers to treat a None default specially by JelleZijlstra · Pull Request #689 · python/peps · GitHub
[go: up one dir, main page]

Skip to content

PEP 484: Do not require type checkers to treat a None default specially #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2018
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
Next Next commit
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.
  • Loading branch information
JelleZijlstra authored Jul 1, 2018
commit 15740d3b279df566377c38ff4e203fe0ff9577cf
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
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
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
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
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
0