[Python-Dev] defaultdict and on_missing() (original) (raw)

Guido van Rossum guido at python.org
Wed Feb 22 18:44:33 CET 2006


On 2/22/06, Raymond Hettinger <python at rcn.com> wrote:

[Guido van Rossum"] > If we removed onmissing() from dict, we'd have to override > getitem in defaultdict (regardless of whether we give >defaultdict an onmissing() hook or in-line it).

You have another option. Keep your current modifications to dict.getitem but do not include dict.onmissing(). Let it only be called in a subclass IF it is defined; otherwise, raise KeyError.

OK. I don't have time right now for another round of patches -- if you do, please go ahead. The dict docs in my latest patch must be updated somewhat (since they document on_missing()).

That keeps me happy since the basic dict API won't show onmissing(), but it still allows a user to attach an onmissing method to a dict subclass when or if needed. I think all your test cases would still pass without modification.

Except the ones that explicitly test for dict.on_missing()'s presence and behavior. :-)

This is approach is not much different than for other magic methods which kick-in if defined or revert to a default behavior if not.

Right. Plenty of precedent there.

My core concern is to keep the dict API clean as a whistle.

Understood.

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list