8000 Update signature of `dict.get` by JukkaL · Pull Request #852 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Update signature of dict.get #852

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 1 commit into from
Jan 20, 2017
Merged

Update signature of dict.get #852

merged 1 commit into from
Jan 20, 2017

Conversation

JukkaL
Copy link
Contributor
@JukkaL JukkaL commented Jan 20, 2017

Without this change, mypy can't infer proper types for cases like
d.get(k, []) where it needs type context to infer the type of
[]. We add the value type to the second argument to get using
union types, and this provides the context. This doesn't affect
the effective signature of get, other than providing the type
context for mypy.

Also removed some related redundant method definitions where we can
just inherit the base class definition. This makes it easier to
keep the method signatures consistent.

Note that this requires a few mypy PRs before mypy will be able to
use this effectively:

Without this change, mypy can't infer proper types for cases like
`d.get(k, [])` where it needs type context to infer the type of
`[]`. We add the value type to the second argument to `get` using
union types, and this provides the context. This doesn't affect
the effective signature of `get`, other than providing the type
context for mypy.

Also removed some related redundant method definitions where we can
just inherit the base class definition. This makes it easier to
keep the method signatures consistent.

Note that this requires a few mypy PRs before mypy will be able to
use this effectively:

* python/mypy#2718
* python/mypy#2715
@gvanrossum gvanrossum merged commit f2579e5 into master Jan 20, 2017
@gvanrossum gvanrossum deleted the dict-get branch January 20, 2017 15:41
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.

2 participants
0