-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Why is collections.ChainMap.__missing__
defined in the stub?
#7188
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
Possibly useful for subclasses? Clearly not the most important stub, but the default good reason of "it exists at runtime" applies. Maybe @natemcmaster remembers if they had a specific use case in mind when they contributed #4784 :-) |
Yes, I added it for subclassing. I have a type in my project that overrides |
It seems fine to have this method, although we could consider changing the return type to |
Thanks! Makes sense :) |
Changing to NoReturn would break my usecase since my subclass returns a default value when |
collections.ChainMap.__missing__
is defined in typeshed here:typeshed/stdlib/collections/__init__.pyi
Line 329 in 63489c3
But, at runtime, it always raises
KeyError
(and always has done), so there's no situation in which it would be safe to call this method (it's really just an implementation detail to giveChainMap
a nicer error message for when the key isn't present in any of the underlying mappings, as far as I can tell).The method was added to typeshed in a standalone PR (#4784)... Am I
__missing__
something? Is there a good reason for it to be there?The text was updated successfully, but these errors were encountered: