[New-bugs-announce] [issue15031] Split .pyc parsing from module loading

Ronan Lamy report at bugs.python.org
Thu Jun 7 21:10:13 CEST 2012

New submission from Ronan Lamy <ronan.lamy at gmail.com>:

I think it would be beneficial to extract the handling of the binary format of bytecode files from the rest of the loader/finder code in importlib._bootstrap. That means exposing, internally at least, functions that do nothing more than convert the binary contents of a .pyc file to/from metadata + code object. They would help in testing and implementing alternate loaders and would prevent the kind of code duplication that led to issue 15030.

I'm adding a patch implementing extracting a _loads_pyc() function from _bytes_to_bytecode(). Note that:

* _loads_pyc() has only one parameter, instead of 5 for _bytes_from_bytecode.
* The raising of exceptions is more consistent: _loads_pyc being an IO helper, it never raises ImportError. Thanks to exception chaining, no information is lost, though.

Obviously, this should be complemented with a _dumps_pyc(). Then there's the question of whether these functions should be public and what the best interface is - I actually feel that the natural home of both functions is in a lower level module, either imp or marshal.

So, should I get on with it, or are there things I overlooked that make this a bad idea?

components: Interpreter Core
files: loads_pyc.diff
keywords: patch
messages: 162489
nosy: Ronan.Lamy, brett.cannon, ncoghlan
priority: normal
severity: normal
status: open
title: Split .pyc parsing from module loading
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file25860/loads_pyc.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list