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

Eric Snow ericsnowcurrently at gmail.com
Fri Mar 6 18:10:56 CET 2015


On Fri, Mar 6, 2015 at 9:34 AM, Brett Cannon <bcannon at gmail.com> wrote:
> Not specifying the optimization level when it is at 0
> -----------------------------------------------------
>
> It has been suggested that for the common case of when the
> optimizations are at level 0 that the entire part of the file name
> relating to the optimization level be left out. This would allow for
> file names of ``.pyc`` files to go unchanged, potentially leading to
> less backwards-compatibility issues (although Python 3.5 introduces a
> new magic number for bytecode so all bytecode files will have to be
> regenerated regardless of the outcome of this PEP).
>
> It would also allow a potentially redundant bit of information to be
> left out of the file name if an implementation of Python did not
> allow for optimizing bytecode. This would only occur, though, if the
> interpreter didn't support ``-O`` **and** didn't implement the ast
> module, else users could implement their own optimizations.

The presence of the "opt-0" part in the filename could imply that
there are other supported optimization levels, even when there aren't.
So leaving that out when optimizations aren't supported may be a good
idea.  Perhaps add sys.implementation.supports_optimization or
something like that?  Then only leave "opt-0" off if the
implementation does not support any optimization.

--eric


More information about the Python-Dev mailing list