[Python-Dev] defaultdict and on_missing()
Fredrik Lundh
fredrik at pythonware.com
Wed Feb 22 12:54:28 CET 2006
Raymond Hettinger wrote:
> Aside: Why on_missing() is an oddball among dict methods. When
> teaching dicts to beginner, all the methods are easily explainable ex-
> cept this one. You don't call this method directly, you only use it
> when subclassing, you have to override it to do anything useful, it
> hooks KeyError but only when raised by __getitem__ and not
> other methods, etc.
agreed.
> My recommendation: Dump the on_missing() hook. That leaves
> the dict API unmolested and allows a more straight-forward im-
> plementation/explanation of collections.default_dict or whatever
> it ends-up being named. The result is delightfully simple and easy
> to understand/explain.
agreed.
a separate type in collections, a template object (or factory) passed to
the constructor, and implementation inheritance, is more than good en-
ough. and if I recall correctly, pretty much what Guido first proposed.
I trust his intuition a lot more than I trust the design-by-committee-with-
out-use-cases process.
</F>
More information about the Python-Dev
mailing list