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 steven.daprano
Date 2020-03-01.03:42:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583034162.79.0.0576327457429.issue39805@roundup.psfhosted.org>
In-reply-to
Content
Function objects are mutable, so I expected that a copy of a function should be an actual independent copy. But it isn't.

    py> from copy import copy
    py> a = lambda: 1
    py> b = copy(a)
    py> a is b
    True

This burned me when I modified the copy and the original changed too:

    py> a.attr = 27  # add extra data
    py> b.attr = 42
    py> a.attr
    42


`deepcopy` doesn't copy the function either.
History
Date User Action Args
2020-03-01 03:42:42steven.dapranosetrecipients: + steven.daprano
2020-03-01 03:42:42steven.dapranosetmessageid: <1583034162.79.0.0576327457429.issue39805@roundup.psfhosted.org>
2020-03-01 03:42:42steven.dapranolinkissue39805 messages
2020-03-01 03:42:42steven.dapranocreate