def function_named(fn, name):
 try:
  fn.__name__ = name
 except TypeError:
  fn = types.FunctionType(fn.__code__, fn.__globals__, name, fn.__defaults__, fn.__closure__)
 return fn

def function_named ( fn , name ) : try : fn . __name__ = name except TypeError : fn = types . FunctionType ( fn . __code__ , fn . __globals__ , name , fn . __defaults__ , fn . __closure__ ) return fn
return a function with a given __name__ .