Steven D'Aprano <[email protected]> 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__,
func.__closure__
)
vars(new).update(vars(func))
new.__annotations__.update(func.__annotations__)
if func.__kwdefaults__ is not None:
new.__kwdefaults__ = func.__kwdefaults__.copy()
return new
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39805>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com