[issue39805] Copying functions doesn't actually copy them

2022-03-28 Thread STINNER Victor
STINNER Victor added the comment: See also bpo-47143 "Add functools.copy_class() which updates closures". -- nosy: +vstinner ___ Python tracker ___

[issue39805] Copying functions doesn't actually copy them

2022-02-13 Thread Numerlor
Numerlor added the comment: Having copy be an identity function for anything mutable seems very bug prone, even if it's functions. If not changed in the copy interface I would say that at least a warning would be helpful. -- ___ Python tracker

[issue39805] Copying functions doesn't actually copy them

2022-02-13 Thread Steven D'Aprano
Steven D'Aprano added the comment: If we can't change the default behaviour of copying functions, can we add a specialised copy_function() function, for when we really need to make a genuine copy? -- ___ Python tracker

[issue39805] Copying functions doesn't actually copy them

2022-02-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It is by design. Functions and types are pickled by name. The copy module uses the pickling protocol and only use different methods for performance or for non-pickleable objects. Changing this will break existing code. -- nosy: +serhiy.storchaka

[issue39805] Copying functions doesn't actually copy them

2022-02-12 Thread Numerlor
Numerlor added the comment: Ran into this myself today; do you have any plans on implementing the proposed change? -- nosy: +Numerlor ___ Python tracker ___

[issue39805] Copying functions doesn't actually copy them

2020-02-29 Thread Steven D'Aprano
Steven D'Aprano added the comment: I think this is sufficient for a shallow copy. import copy import types def copyfunction(func): new = types.FunctionType( func.__code__, func.__globals__, func.__name__, func.__defaults__,

[issue39805] Copying functions doesn't actually copy them

2020-02-29 Thread Steven D'Aprano
New submission from Steven D'Aprano : 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