Title: Switching from -OO to -O still uses cached bytecode
Type: Stage:
Components: Versions: Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: pyo's are not overwritten by different optimization levels
View: 1538778
Assigned To: Nosy List: Matthew.Fernandez, barry, brett.cannon, pitrou
Priority: normal Keywords:

Created on 2014-05-12 23:56 by Matthew.Fernandez, last changed 2014-05-13 15:32 by brett.cannon. This issue is now closed.

Messages (4)
msg218385 - (view) Author: Matthew Fernandez (Matthew.Fernandez) Date: 2014-05-12 23:56
Perhaps others wouldn't consider this a bug, but it was definitely surprising to me. When switching between optimisation levels -OO (optimise and strip docstrings) and -O (just optimise), you will find the docstrings are still stripped. E.g.

$ ls
$ cat
import world
$ cat
def foo():
    '''I'm a docstring'''

import sys
print 'optimization: %d' % sys.flags.optimize
if sys.flags.optimize < 2:
    print foo.__doc__
    print 'optimisation is enabled; no docstrings'
$ python -OO
optimization: 2
optimisation is enabled; no docstrings
$ python -O
optimization: 1
$ rm world.pyo
$ python -O
optimization: 1
I'm a docstring

Is this behaviour intentional?
msg218387 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-05-13 00:04
Not really intentional, it's just a limitation of the current implementation (where the same .pyo files are used for both -O and -OO). Already reported as issue1538778 (which was closed as won't fix).
msg218390 - (view) Author: Matthew Fernandez (Matthew.Fernandez) Date: 2014-05-13 00:22
Ah thanks, Antoine. Sorry, failed to find that issue in my prior searching.
msg218465 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-05-13 15:32
It's something that could potentially be changed in the future, but no one has prioritized it enough to worry about it. Typically this opens a pandora's box of wanting to generalize it so it supports custom user optimizations as well and then people lose motivation to push it through to the end. =)
Date User Action Args
2014-05-13 15:32:17brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg218465

resolution: duplicate
2014-05-13 00:22:18Matthew.Fernandezsetmessages: + msg218390
2014-05-13 00:04:51pitrousetnosy: + barry, pitrou
superseder: pyo's are not overwritten by different optimization levels
messages: + msg218387
2014-05-12 23:56:36Matthew.Fernandezcreate