kwargs.copy()

The coding guide recommends that any **kwargs dictionary that is passed into a function should be copied so that the original is unaffected when items are popped off inside the function. I noticed that this is not done by pylab functions generated by boilerplate.py, and in fact I don't think it is necessary:

In [9]:def test2(**kw):
    ...: first = kw.pop('a')
    ...: print first
    ...: print kw
    ...:

In [10]:test2(**kw)
c
{'b': 'd'}

In [11]:kw
Out[11]:{'a': 'c', 'b': 'd'}

Popping the 'a' entry inside the function did not affect the dictionary that was passed in; it evidently gets copied automatically.

Am I missing something? Or should I go ahead and strip out the extra copies and modify the corresponding advice in CODING_GUIDE?

Eric

Well, that was certainly a surprise to me -- yep all the copying of
**kwargs can be eliminated and the CODING_GUIDE updated. Thanks for
discovering this and pointing it out!

JDH

···

On 3/26/07, Eric Firing <efiring@...229...> wrote:

Popping the 'a' entry inside the function did not affect the dictionary
that was passed in; it evidently gets copied automatically.

Am I missing something? Or should I go ahead and strip out the extra
copies and modify the corresponding advice in CODING_GUIDE?