def renamefunction(function, name):
	"""
	This function returns a function identical to the given one, but
	with the given name.
	"""
	from types import FunctionType, CodeType

	c = function.func_code
	if c.co_name != name:
		# rename the code object.
		c = CodeType(c.co_argcount, c.co_nlocals, c.co_stacksize,
					 c.co_flags, c.co_code, c.co_consts,
					 c.co_names, c.co_varnames, c.co_filename,
					 name, c.co_firstlineno, c.co_lnotab)
	if function.func_defaults != None:
		return FunctionType(c, function.func_globals, name,
							function.func_defaults)
	return FunctionType(c, function.func_globals, name)

	This function returns a function identical to the given one, but
	with the given name.
	
recipes/Python/223613_Install_bound_methods/recipe-223613.py