New submission from Steven D'Aprano <steve+pyt...@pearwood.info>:
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. ---------- components: Library (Lib) messages: 363039 nosy: steven.daprano priority: normal severity: normal status: open title: Copying functions doesn't actually copy them type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39805> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com