[Python-Dev] Intention to accept PEP 552 soon (deterministic pyc files)

Barry Warsaw barry at python.org
Thu Oct 5 09:44:24 EDT 2017


On Oct 4, 2017, at 13:53, Benjamin Peterson <benjamin at python.org> wrote:

> It might be helpful to enumerate the usecases for such an API. Perhaps a
> narrow, specialized API could satisfy most needs in a supportable way.

Currently `python -m dis thing.py` compiles the source then disassembles it.  It would be kind of cool if you could pass a .pyc file to -m dis, in which case you’d need to unpack the header to get to the code object.  A naive implementation would unpack the magic number and refuse to disassemble any files that don’t match whatever that version of Python understands.  A more robust (possibly 3rd party) implementation could potentially disassemble a range of magic numbers and formats, and an API to get at the code object and metadata would help.

I was thinking about the bytecode hacking that some debuggers do.  This API would help them support multiple versions of Python.  They could use the API to discover what pyc format was in use, extract the code object, hack the bytecode and possibly rewrite a new PEP 3147 style pyc file with the debugger bytecodes inserted.

Third party bytecode optimizers could use the API to unpack multiple versions of pyc files, do their optimizations, and rewrite new files with the proper format.

Cheers,
-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171005/630d1d7c/attachment-0001.sig>


More information about the Python-Dev mailing list