[New-bugs-announce] [issue21489] Switching from -OO to -O still uses cached bytecode

Matthew Fernandez report at bugs.python.org
Tue May 13 01:56:36 CEST 2014

New submission from Matthew Fernandez:

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
hello.py world.py
$ cat hello.py
import world
$ cat world.py
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 hello.py
optimization: 2
optimisation is enabled; no docstrings
$ python -O hello.py
optimization: 1
$ rm world.pyo
$ python -O hello.py
optimization: 1
I'm a docstring

Is this behaviour intentional?

messages: 218385
nosy: Matthew.Fernandez
priority: normal
severity: normal
status: open
title: Switching from -OO to -O still uses cached bytecode
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list