[Python-Dev] PEP 488: elimination of PYO files

Steven D'Aprano steve at pearwood.info
Sat Mar 7 10:58:59 CET 2015


On Fri, Mar 06, 2015 at 08:00:20PM -0500, Ron Adam wrote:

> Have you considered doing this by having different magic numbers in the 
> .pyc file for standard, -O, and -O0 compiled bytecode files?  Python 
> already checks that number and recompiles the files if it's not what it's 
> expected to be.  And it wouldn't require any naming conventions or new 
> cache directories.  It seems to me it would be much easier to do as well.

And it would fail to solve the problem. The problem isn't just that the 
.pyo file can contain the wrong byte-code for the optimization level, 
that's only part of the problem. Another issue is that you cannot have 
pre-compiled byte-code for multiple different optimization levels. You 
can have a "no optimization" byte-code file, the .pyc file, but only one 
"optimized" byte-code file at the same time.

Brett's proposal will allow -O optimized and -OO optimized byte-code 
files to co-exist, as well as setting up a clear naming convention for 
future optimizers in either the Python compiler or third-party 
optimizers.

No new cache directories are needed. The __pycache__ directory has been 
used since Python 3.3 (or was it 3.2? I forget which). 



-- 
Steve


More information about the Python-Dev mailing list