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 steven.daprano
Recipients TenzinCHW, steven.daprano
Date 2021-03-22.09:56:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1616406972.0.0.349963061793.issue43589@roundup.psfhosted.org>
In-reply-to
Content
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)
        ...
History
Date User Action Args
2021-03-22 09:56:12steven.dapranosetrecipients: + steven.daprano, TenzinCHW
2021-03-22 09:56:12steven.dapranosetmessageid: <1616406972.0.0.349963061793.issue43589@roundup.psfhosted.org>
2021-03-22 09:56:11steven.dapranolinkissue43589 messages
2021-03-22 09:56:11steven.dapranocreate