Issue 19531: Loading -OO bytecode files if -O was requested can lead to problems (original) (raw)

Issue19531

Created on 2013-11-09 05:57 by deleted250130, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg202462 - (view) Author: (deleted250130) Date: 2013-11-09 05:57
The documentation says that -OO does remove docstrings so applications should be aware of it. But there is also a case where a valid declared docstring isn't accessible anymore if -O is given. First the testcase: test1.py: import test2 def test1(): """test1""" print(test1.__doc__) print(test2.test2.__doc__) test2.py: def test2(): """test2""" A simple check will show the current result: sworddragon@ubuntu:~/tmp$ python3 -BO test1.py test1 test2 If -OO is given the docstrings will be removed as expected: sworddragon@ubuntu:~/tmp$ python3 -OO test1.py None None Now we have also bytecode files saved on the disk without any docstrings. But if we try to use only -O the problem appears: sworddragon@ubuntu:~/tmp$ python3 -O test1.py test1 None Even with only -O given we doesn't get the docstring for the imported module. The problem is that Python allows to load -OO bytecode files if -O bytecode was requested. I think the simplest solution would be to name -OO bytecode-files as .pyoo.
msg202475 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-11-09 09:09
Some tests fail when ran with -OO and then with -O. Short example (there are more examples): $ rm -rf Lib/test/__pycache__ $ ./python -OO -m test.regrtest test_property [1/1] test_property 1 test OK. $ ./python -O -m test.regrtest test_property [1/1] test_property test test_property failed -- multiple errors occurred; run in verbose mode for details 1 test failed: test_property
msg202484 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-11-09 16:04
This is a known problem and has been brought up over the years. Discussions have typically revolved around expanding the .pyc format to encode what optimizations were used so if the interpreter was using different optimizations it would not use the bytecode.
msg363549 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-03-06 20:40
.pyc files now include their optimization levels in their file names.
History
Date User Action Args
2022-04-11 14:57:53 admin set github: 63730
2020-03-06 20:40:08 brett.cannon set status: open -> closedresolution: fixedmessages: + stage: resolved
2014-05-22 22:13:27 skrah set nosy: - skrah
2013-11-09 16:04:01 brett.cannon set nosy: + brett.cannonmessages: +
2013-11-09 09:09:07 serhiy.storchaka set versions: + Python 2.7, Python 3.4nosy: + skrah, serhiy.storchakamessages: + components: + Teststype: enhancement -> behavior
2013-11-09 05:57:27 deleted250130 create