-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
The type of __default= in dict.pop and dict.get doesn't look right #10293
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
Yes, I think you're right. Feel free to send a PR! |
Will do! |
I'm a little confused. In your example, why would But I'm fine with anything as long as the following three cases type check:
|
Ooops, sorry. I was meaning to write I think all three cases should type check with the proposed definition. |
Okay, another correction. The right signature for seems to be
because a |
Fixes #10293 Co-authored-by: AlexWaygood <[email protected]>
dict.pop
is currently defined astypeshed/stdlib/builtins.pyi
Lines 1086 to 1089 in 1851423
Note the union with two type parameters as a type of
__default=
. This type is ambiguous ifdict.pop
is called with a value of type_VT
. For example, givena type checker can choose any value for
_T
, sincestr
is a subtype ofstr | _T
regardless of what_T
is.It seems the union was introduced in 2fdcd2e, which unfortunately does not seem to give any reasoning for that. I think we should drop it and use
_T
instead in bothdict.pop
anddict.get
(and similarly forMutableMapping
), i.e.The text was updated successfully, but these errors were encountered: