On Fri, 1 Apr 2022 at 19:51, Victor Stinner <[email protected]> wrote:
> In Python, sadly the types.CodeType type also has a public constructor
> and many projects break at each Python release because the API
> changes. Hopefully, it seems like the new CodeType.replace() method
> added to Python 3.8 mitigated the issue. IMO CodeType.replace() is a
> better abstraction and closer to what developers need in practice.

It certainly has been for me. When I want to do bytecode hackery, I
usually start by creating a function with def/lambda, then construct a
modified function using f.__code__.replace(). It's the easiest way to
ensure that all the little details are correct.

ChrisA
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/JJO6LDWA4BE7SFTEF2VP6NLSIX6ZBCGD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to