kwarg references

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 26 01:38:47 EDT 2007


En Tue, 24 Apr 2007 22:31:59 -0300, Calvin Spealman <ironfroggy at gmail.com>  
escribió:

> In the internal API when a C function is called and passed a kwarg
> dictionary, is there any case where anything else has a reference to
> it? I checked with the following code and it looks like even if you
> explicitly pass a dictionary with **kwargs, it still copies the
> dictionary anyway.

See the Python Reference Manual, 5.3.4 Calls
http://docs.python.org/ref/calls.html

Unfortunately it does not explicitely *guarantee* it will be a new  
dictionary. At least the way I read the docs, on a function call like this:

def foo(**kwargs): pass
d = {'a':1, 'b':2)
foo(**d)

Python could bind the existing d object to the formal parameter kwargs and  
still comply with the documented behavior. Some of my own code would break  
if that happened... :(

-- 
Gabriel Genellina



More information about the Python-list mailing list