Monkey patching python modules is waaaaay more straightforward than this.
setattr(mod, name, new_func)