Steven D'Aprano <[email protected]> added the comment:
This is normal, expected behaviour and has nothing to do with defaultdicts
specifically. Any mutable object would behave the same way.
Function default parameters are evaluated only once, when the function is
defined. They are not re-evaluated on each call.
The standard pattern used for re-evaluating the default is:
def function(arg=None):
if arg is None:
arg = defaultdict(list)
...
----------
nosy: +steven.daprano
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43589>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com