overloading *something

Robert Kern robert.kern at gmail.com
Wed Nov 9 07:54:36 CET 2005

James Stroud wrote:

> Does anyone else find the following annoying:
> py> from UserDict import UserDict
> py> aud = UserDict({"a":1, "b":2})
> py> def doit(**kwargs):
> ...   print kwargs
> ...
> py> aud
> {'a': 1, 'b': 2}
> py> doit(**aud)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: doit() argument after ** must be a dictionary
> UserDict should be isomorphic with a dict. The fact that it is not in this 
> case seems terribly un-pythonic to me.

UserDict only exists for backwards compatibility with old code that used
it before one could subclass from dict directly. Don't use it if you can
avoid it. UserDict only ever exposed the Python-side interface of dicts.
It couldn't expose the C-side interface, and it's the C-side interface
that **kwds is using.

Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

More information about the Python-list mailing list