Duck Typing and **kwds
Luis Zarrabeitia
kyrie at uh.cu
Thu Oct 11 00:05:10 EDT 2007
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?
Regards,
--
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie
--
"Al mundo nuevo corresponde la Universidad nueva"
UNIVERSIDAD DE LA HABANA
280 aniversario
More information about the Python-list
mailing list