Message363039
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. |
|
Date |
User |
Action |
Args |
2020-03-01 03:42:42 | steven.daprano | set | recipients:
+ steven.daprano |
2020-03-01 03:42:42 | steven.daprano | set | messageid: <1583034162.79.0.0576327457429.issue39805@roundup.psfhosted.org> |
2020-03-01 03:42:42 | steven.daprano | link | issue39805 messages |
2020-03-01 03:42:42 | steven.daprano | create | |
|