#NEWLINE# def mergeFunctionMetadata( f , g ) : #NEWLINE# #INDENT# "\n    Overwrite C{g}'s name and docstring with values from C{f}.  Update\n    C{g}'s instance dictionary with C{f}'s.\n\n    To use this function safely you must use the return value. In Python 2.3,\n    L{mergeFunctionMetadata} will create a new function. In later versions of\n    Python, C{g} will be mutated and returned.\n\n    @return: A function that has C{g}'s behavior and metadata merged from\n        C{f}.\n    " #NEWLINE# try : #NEWLINE# #INDENT# g . __name__ = f . __name__ #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# merged = types . FunctionType ( g . func_code , g . func_globals , f . __name__ , inspect . getargspec ( g ) [ ( - 1 ) ] , g . func_closure ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# merged = g #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# merged . __doc__ = f . __doc__ #NEWLINE# #UNINDENT# except ( TypeError , AttributeError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# merged . __dict__ . update ( g . __dict__ ) #NEWLINE# merged . __dict__ . update ( f . __dict__ ) #NEWLINE# #UNINDENT# except ( TypeError , AttributeError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# merged . __module__ = f . __module__ #NEWLINE# return merged