Message389289
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. |
|
Date |
User |
Action |
Args |
2021-03-22 09:15:29 | TenzinCHW | set | recipients:
+ TenzinCHW |
2021-03-22 09:15:29 | TenzinCHW | set | messageid: <1616404529.38.0.239841546052.issue43589@roundup.psfhosted.org> |
2021-03-22 09:15:29 | TenzinCHW | link | issue43589 messages |
2021-03-22 09:15:29 | TenzinCHW | create | |
|