Duck Typing and **kwds

Luis Zarrabeitia kyrie at
Thu Oct 11 06:05:10 CEST 2007

Hi there.

I just tried this test:

def f(**kwds):
    print kwds

import UserDict
d = UserDict.UserDict(hello="world")

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?


Luis Zarrabeitia
Facultad de Matemática y Computación, UH

"Al mundo nuevo corresponde la Universidad nueva"
280 aniversario 

More information about the Python-list mailing list