overloading *something

James Stroud jstroud at mbi.ucla.edu
Wed Nov 9 21:51:36 CET 2005


On Tuesday 08 November 2005 22:54, Robert Kern wrote:
> 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.

That **kwargs insists on using the C-side interface is precisely the annoyance 
to which I am referring. I should be able to write a dictionary-like 
interface in python and **kwargs should in turn be able to use it. If the 
retort is that the C-side interface is used for performance, my retort to the 
retort is that an isinstance() is already being called somewhere, so no 
additional tests would need to be made to make **kwargs more generalized.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list