Skip to content

Fix simplification of some unions #2718

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

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 19, 2017

In particular, this helps with classes that have Any base classes.

This is enough to fix #2712. This is almost a subset of #2714
and should land before that, as this should cause less disruption.

In particular, this helps with classes that have Any base classes.

This is enough to fix #2712. This is almost a subset of #2714
and should land before that, as this should cause less disruption.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 19, 2017

The reason I made this is because #2714 generates many new errors when run against internal Dropbox repos, and I'd rather not track these down right now. This should be enough to let us use recent typeshed revisions (together with some other fixes). The new errors caused by #2714 look mostly legitimate, though, and we'll want to investigate them eventually.

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 9496d6f into master Jan 20, 2017
@gvanrossum gvanrossum deleted the small-union-simplify-fix branch January 27, 2017 19:37
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.

Union of a class with Any base and None is sometimes None
2 participants