Using the Python function syntax def f(**kwargs)
, in the function a keyword argument dictionary kwargs
is created, and dictionaries are mutable, so the
For Python-level code, the kwargs
dict inside a function will always be a new dict.
For C extensions, though, watch out. The C API version of kwargs
will sometimes pass a dict through directly. In previous versions, it would even pass dict subclasses through directly, leading to the bug (now fixed) where
'{a}'.format(**collections.defaultdict(int))
would produce '0'
instead of raising a KeyError
.
If you ever have to write C extensions, possibly including Cython, don't try to modify the kwargs
equivalent, and watch out for dict subclasses on old Python versions.