This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author TenzinCHW
Recipients TenzinCHW
Date 2021-03-22.09:15:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616404529.38.0.239841546052.issue43589@roundup.psfhosted.org>
In-reply-to
Content
When using a `defaultdict` as a kwarg to a function that requires another argument, every call to the function uses the same dictionary instance instead of creating a new one.

```>>> from collections import defaultdict
>>> def meow(a, b=defaultdict(list)):
...     b[a].append('moo')
...     return b
... 
>>> c = meow('hi')
>>> c
defaultdict(<class 'list'>, {'hi': ['moo']})
>>> c = meow('bye')
>>> c
defaultdict(<class 'list'>, {'hi': ['moo'], 'bye': ['moo']})
>>> d = meow('hello')
>>> d
defaultdict(<class 'list'>, {'hi': ['moo'], 'bye': ['moo'], 'hello': ['moo']})```

Is this the correct behaviour? Occurred in 3.6.12, 3.7.9, 3.8.5, 3.8.6 and 3.9.0.
History
Date User Action Args
2021-03-22 09:15:29TenzinCHWsetrecipients: + TenzinCHW
2021-03-22 09:15:29TenzinCHWsetmessageid: <1616404529.38.0.239841546052.issue43589@roundup.psfhosted.org>
2021-03-22 09:15:29TenzinCHWlinkissue43589 messages
2021-03-22 09:15:29TenzinCHWcreate