[Python-Dev] #12982: Should -O be required to *read* .pyo files?

Steven D'Aprano steve at pearwood.info
Thu Jun 14 05:25:25 CEST 2012


On Wed, Jun 13, 2012 at 09:54:30PM -0400, Terry Reedy wrote:

> >So, no, we
> 
> You mean the interpreter?

Yes.

> >should never use
> 
> Do you mean import or execute?
> Current, the interpreter executes any bytecode that gets imported.

Both.

> >.pyo files unless explicitly told to do so,
> 
> What constitutes 'explicitly told to do so'? Currently, an 'optimized' 
> file written as .pyo gets imported (and hence executed) if
> 1) the interpreter is started with -O
> 2) a custom importer ignores the absence of -O
> 3) someone renames x.pyo to x.pyc.

Any of the above are fine by me.

I oppose this one:

4) the interpreter is started without -O but there is no .pyc file.

since it can lead to a mismatch between what I (the developer) thinks is 
being run and what is actually being run (or imported).

For the avoidance of doubt, if my end-users secretly rename .pyo to .pyc 
files, that's my problem, not the Python's interpreter's problem. I 
don't expect Python to be idiot-proof.



-- 
Steven



More information about the Python-Dev mailing list