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 give ChainMap 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?
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 :-)
Activity
hauntsaninja commented on Feb 14, 2022
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 :-)
natemcmaster commented on Feb 15, 2022
Yes, I added it for subclassing. I have a type in my project that overrides ChainMap.__getitem__ and calls __missing__
srittau commented on Feb 15, 2022
It seems fine to have this method, although we could consider changing the return type to NoReturn.
AlexWaygood commented on Feb 15, 2022
Thanks! Makes sense :)
natemcmaster commented on Feb 15, 2022
Changing to NoReturn would break my usecase since my subclass returns a default value when __missing__ is called, similar to defaultdict. https://docs.python.org/3/library/collections.html#collections.defaultdict.missing