Skip to content

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.

3 participants