New submission from Tenzin <tenzin_c...@mymail.sutd.edu.sg>:
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. ---------- messages: 389289 nosy: TenzinCHW priority: normal severity: normal status: open title: Using defaultdict as kwarg to function reuses same dictionary every function call type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43589> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com