Comment

Comment by hardenedapple

As a curiosity/hack you can almost get there with pyrasite (https://github.com/lmacken/pyrasite) and

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.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton