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. |