This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: split existing optimization levels into granular options
Type: enhancement Stage:
Components: Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, carljm, eric.snow, lukasz.langa, ncoghlan, serhiy.storchaka, steven.daprano, vstinner
Priority: normal Keywords:

Created on 2018-05-14 16:18 by carljm, last changed 2022-04-11 14:59 by admin.

Messages (6)
msg316531 - (view) Author: Carl Meyer (carljm) * Date: 2018-05-14 16:18
It doesn't make sense for e.g. docstring-stripping to necessarily imply assert-stripping. These are totally separate options, useful for separate reasons, but currently tied together in the `-O` option.

This is not just a theoretical problem; at work we must strip docstrings in production for memory reasons, but we would prefer not to strip asserts. In fact we currently lint against use of `assert` because it is stripped in production, and we replace it with our own assertion function, which is less efficient and also integrates poorly with mypy's type binder.

A better option would be to enable each of these separate optimizations with a separate command-line flag (probably a string tag passed to a single flag, e.g. `-o strip_docstrings`).

PYC filename generation will also need to include all individually-enabled optimization string tags as part of the filename.

For backwards-compatibility, the existing `-O` flags should still be supported with the same meaning they currently have; `-O` and the new granular `-o` should be additive.

(A version of this was previously proposed as a minor part of PEP 511.)

Please let me know if this proposal is of sufficient complexity that a PEP is needed instead of just an issue.
msg316544 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-05-14 18:06
Reference to some discussions on this topic https://groups.google.com/forum/#!topic/python-ideas/4oRgwrV1tVA
msg316905 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-05-17 10:38
PSF link for Diana Clark's thread on python-ideas about this: https://mail.python.org/pipermail/python-ideas/2017-September/047224.html (this is the same thread Brett linked, just to the PSF archives rather than Google Groups)
msg316908 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-17 10:46
Isn't this a duplicate of the old issue2506?
msg316926 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-05-17 13:27
I don't thnk they are quite the same. The other issue is about turning off the peepholer entirely while this one is about breaking up the optimizations that -O and -OO do so you can choose which ones you want (e.g. still drop docstrings but keep asserts).
msg317080 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-19 00:36
I'm not sure that the bug tracker is the best place to propose such idea. Maybe start a new thread on python-ideas?
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77682
2018-05-19 00:36:17vstinnersetmessages: + msg317080
2018-05-17 13:27:19brett.cannonsetmessages: + msg316926
2018-05-17 10:46:17serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg316908
2018-05-17 10:38:55ncoghlansetmessages: + msg316905
2018-05-14 18:06:01brett.cannonsetmessages: + msg316544
2018-05-14 16:20:24steven.dapranosetnosy: + steven.daprano
2018-05-14 16:18:37carljmcreate