[Python-Dev] Proposal: defaultdict (original) (raw)

Guido van Rossum guido at python.org
Sat Feb 18 00:00:22 CET 2006


On 2/17/06, Adam Olsen <rhamph at gmail.com> wrote:

> Such are the joys of writing polymorphic code. I don't really see how > you can avoid this kind of confusion -- I could have given you some > other mapping object that does weird stuff.

You could pass a float in as well. But if the function is documented as taking a dict, and the programmer expects a dict.. that now has to be changed to "dict without a default". Or they have to code defensively since d[key] may or may not raise KeyError, so they must avoid depending on it either way.

I'd like to see a real-life example of code that would break this way. I believe that most code that takes a dict will work just fine if that dict has a default factory.

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



More information about the Python-Dev mailing list