Python 3.11+ partial workaround
Description
I need the ability to obtain function source code at runtime for various introspection purposes. Since Python 3.9+, and Python3.11 even more, cannot be easily decompiled, I cheated. The results are here.
While properly decompiling code is needed for dynamically generated code, complex template logic, and when you don't have the original source code available, sometimes it's sufficient to simply automate fetching the relevant lines of source code out of the source file.
The fake decompiler is zlib licensed, so you're welcome to hoist it into your own stuff if you like, or just link to it on the readme. Hopefully it will be of some use.
~~Note that I'm out of time to implement recreating the function signature to support lambdas better. It should take maybe half an hour to do, just need to extract the arguments and stringify them suitably.~~ Faking signatures works.
BUMP Consider updating to support Python 3.11/12.
I looked at the code mentioned. I apologize, but I don't understand exactly what problem it solves in a specific sense or how one would use this. Maybe making a video or asciinema screencast would help?
As for decopilation of more recent Python, try https://pylingual.io.
I will be giving a talk on October 18th at BSidesNYC 2025, where I'll describe various approaches to understanding and working with Python bytecode when there is no source code.