Skip to content
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

use explicit Optional[...] for parameters with None as a default in datastructures.py #1448

Merged
merged 5 commits into from
Jan 31, 2022

Conversation

adriangb
Copy link
Member

@adriangb adriangb commented Jan 29, 2022

@adriangb adriangb changed the title use explicit Optional[...] for paramters with None as a default use explicit Optional[...] for parameters with None as a default in datastructures.py Jan 29, 2022
@Kludex
Copy link
Sponsor Member

Kludex commented Jan 30, 2022

See https://www.python.org/dev/peps/pep-0484/#id29

The link is "not found".

@adriangb
Copy link
Member Author

adriangb commented Jan 30, 2022

Weird, it got mangled, it should be https://www.python.org/dev/peps/pep-0484/#union-types

@adriangb
Copy link
Member Author

Specifically:

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

Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

Sure. Don't know what the motivation is behind...

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

But happy enough either ways. 😌

@Kludex Kludex merged commit d6269e2 into encode:master Jan 31, 2022
@adriangb adriangb deleted the use-explicit-optional branch January 31, 2022 15:21
@adriangb
Copy link
Member Author

There's probably discussions on the topic in BPO and such. Personally my motivation is just to make sure the project works as well as possible with type checkers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants