Skip to content

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 19, 2017

This helps with the new definition of dict.get in typeshed.

The fix feels a little ad-hoc, but it seems to fix a real-world issue
and doesn't seem to break anything.

Fixes #2703.

This helps with the new definition of `dict.get` in typeshed.

The fix feels a little ad-hoc, but it seems to fix a real-world issue
and doesn't seem to break anything.

Fixes #2703.
JukkaL added a commit to python/typeshed that referenced this pull request 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:

* python/mypy#2718
* python/mypy#2715
gvanrossum pushed a commit to python/typeshed that referenced this pull request 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:

* python/mypy#2718
* python/mypy#2715
@gvanrossum gvanrossum merged commit 5d17006 into master Jan 20, 2017
@gvanrossum gvanrossum deleted the union-context branch January 20, 2017 18:10
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.

Type context not working for second argument of dict.get

3 participants