#NEWLINE# def copy_function( orig , copy_dict = True ) : #NEWLINE# #INDENT# 'Returns a shallow copy of the function, including code object,\n    globals, closure, etc.\n\n    >>> func = lambda: func\n    >>> func() is func\n    True\n    >>> func_copy = copy_function(func)\n    >>> func_copy() is func\n    True\n    >>> func_copy is not func\n    True\n\n    Args:\n        orig (function): The function to be copied. Must be a\n            function, not just any method or callable.\n        copy_dict (bool): Also copy any attributes set on the function\n            instance. Defaults to ``True``.\n    ' #NEWLINE# ret = FunctionType ( orig . __code__ , orig . __globals__ , name = ret . __name__ , argdefs = getattr ( orig , '__defaults__' , None ) , closure = getattr ( orig , '__closure__' , None ) ) #NEWLINE# if copy_dict : #NEWLINE# #INDENT# ret . __dict__ . update ( orig . __dict__ ) #NEWLINE# #UNINDENT# return ret