Duck Typing and **kwds

Eduardo O. Padoan eduardo.padoan at gmail.com
Thu Oct 11 08:53:57 EDT 2007


On 10/11/07, Luis Zarrabeitia <kyrie at uh.cu> wrote:
>
> Hi there.
>
> I just tried this test:
>
> ====
> def f(**kwds):
>     print kwds
>
> import UserDict
> d = UserDict.UserDict(hello="world")
> f(**d)
> ====
>
> And it fails with a TypeError exception ("f() argument after ** must be a
> dictionary"). I find that weird, as UserDict should support all protocols that
> dict supports, yet it doesn't seem to support ** unpacking. If instead of
> UserDict I use a derivate class from dict (class mydict(dict):pass), the **
> operator works as expected. It also works if I execute f(**dict(d)) instead.
>
> Is that behavior expected? Is there any reason (performance, perhaps?) to break
> duck-typing in this situation?

Reported, accepted and closed 5 months ago:
http://bugs.python.org/issue1686487

-- 
http://www.advogato.org/person/eopadoan/
Bookmarks: http://del.icio.us/edcrypt



More information about the Python-list mailing list