Re: Dict __missing__ consistency issues.

[Bar Harel]
As for get(). Current implementation of UserDict returns the default value for get() if __missing__() raises KeyError. Which sounds reasonable to me. After all, you would logically expect __missing__ to be called for get() as you tried to get a non-existing value.
[Ethan Furman] I disagree. My understanding of the purpose behind get() is to get a value or return the default specified in the get() call, not to create a new key (which the default __missing__ does).
There is no default __missing__. That's what the __missing__ at defaultdict does. Like I said before: The fact __missing__ is not called for missing values is a bit funny in my opinion, but it doesn't actually matter cause we can't do anything about it without breaking lots of stuff (e.g. making defaultdict.get worthless).
participants (1)
-
Bar Harel