-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Mapping.{get,pop} can return default type #278
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
Comments
See also python/mypy#738 and python/mypy#1114. |
gvanrossum
pushed a commit
that referenced
this issue
Sep 15, 2016
Fixes #278. The approach here is different from what we thought before. According to this commit, there are three valid forms of Mapping[K, V].get(): d.get() # returns Optional[V] d.get(None) # also returns Optional[V] (seen in the wild) d.get(v) # requires v to have type V, and returns V So we don't allow d.get(d) where d is a type unrelated to V. This is a compromise, but I don't think there's much use for d.get(d) with a default that is differently-typed than V, and when I tried it my application code (that didn't use this) wouldn't type-check correctly.
I think it's fixed for |
Oh yeah. And we use the pop version a lot. That sounds like something I can help out with. |
euresti
pushed a commit
to euresti/typeshed
that referenced
this issue
Mar 20, 2017
This is particularly useful for the idiom `d.pop(k, None)` to remove an item if it exists. Fixes python#278
ambv
pushed a commit
that referenced
this issue
Mar 20, 2017
This is particularly useful for the idiom `d.pop(k, None)` to remove an item if it exists. Fixes #278
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See #223. That PR was reverted because it caused some type errors that it shouldn't, but it's the right thing to do and we should figure out how to make it work.
@gvanrossum , what did the errors you saw (after python/mypy#1595 was fixed) look like?
The text was updated successfully, but these errors were encountered: