Returns a copy of a function f.
(f)
| 1182 | |
| 1183 | |
| 1184 | def copy_func(f): |
| 1185 | """Returns a copy of a function f.""" |
| 1186 | # Based on http://stackoverflow.com/a/6528148/190597 (Glenn Maynard) |
| 1187 | g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__, argdefs=f.__defaults__, closure=f.__closure__) |
| 1188 | g = functools.update_wrapper(g, f) |
| 1189 | g.__kwdefaults__ = f.__kwdefaults__ |
| 1190 | return g |
no outgoing calls
no test coverage detected