Comment Comment by hardenedapple As a curiosity/hack you can almost get there with pyrasite (https://github.com/lmacken/pyrasite) anddef newfn(): ...oldfn.__code__ = newfn.__code__del newfnThere's a difficulty with __globals__ and __closures__ but I found the patch at the end of this post https://hardenedapple.github.io/stories/computers/python_fun... appears to allow full redefinition.Disclaimer: I'm pretty confident there will be edge cases and/or bugs with these approaches. parent hardenedapple 9 years ago
def newfn(): ...
oldfn.__code__ = newfn.__code__
del newfn
There's a difficulty with __globals__ and __closures__ but I found the patch at the end of this post https://hardenedapple.github.io/stories/computers/python_fun... appears to allow full redefinition.
Disclaimer: I'm pretty confident there will be edge cases and/or bugs with these approaches.