Turns out you can modify the __code__ attribute on functions in #Python. You could make a really elegant patching library I think.