Skip to content

bpo-17232: Clarify docs for -O and -OO command line options #5839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,23 @@ Miscellaneous options

.. cmdoption:: -O

Turn on basic optimizations. See also :envvar:`PYTHONOPTIMIZE`.
Remove assert statements and any code conditional on the value of
:const:`__debug__`. Augment the filename for compiled
(:term:`bytecode`) files by adding ``.opt-1`` before the ``.pyc``
extension (see :pep:`488`). See also :envvar:`PYTHONOPTIMIZE`.

.. versionchanged:: 3.5
Modify ``.pyc`` filenames according to :pep:`488`.


.. cmdoption:: -OO

Discard docstrings in addition to the :option:`-O` optimizations.
Do :option:`-O` and also discard docstrings. Augment the filename
for compiled (:term:`bytecode`) files by adding ``.opt-2`` before the
``.pyc`` extension (see :pep:`488`).

.. versionchanged:: 3.5
Modify ``.pyc`` filenames according to :pep:`488`.


.. cmdoption:: -q
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify docs for -O and -OO. Patch by Terry Reedy.
7 changes: 5 additions & 2 deletions Misc/python.man
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ for the named module and runs the corresponding
file as a script.
.TP
.B \-O
Turn on basic optimizations. Given twice, causes docstrings to be discarded.
Remove assert statements and any code conditional on the value of
__debug__; augment the filename for compiled (bytecode) files by
adding .opt-1 before the .pyc extension.
.TP
.B \-OO
Discard docstrings in addition to the \fB-O\fP optimizations.
Do \fB-O\fP and also discard docstrings; change the filename for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheryl, can you explain the \fB, \fP markup and verify that you somehow tested that it does 'the right thing'? I looked at both the web page and python -h output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I changed the line, I kept that part from the original line and simply add the other text around it. However, it appears the Github does attempt to show what will happen with it. If you click on the 'View' button for this source, Github applies the markup in non-raw mode. This shows up as bolded as does some of the text in the -i and -I option that has similar (though not exactly the same) markup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Enough to comfortably merge without personal test.

compiled (bytecode) files by adding .opt-2 before the .pyc extension.
.TP
.B \-q
Do not print the version and copyright messages. These messages are
Expand Down
6 changes: 4 additions & 2 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ static const char usage_2[] = "\
if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
-I : isolate Python from the user's environment (implies -E and -s)\n\
-m mod : run library module as a script (terminates option list)\n\
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\
-OO : remove doc-strings in addition to the -O optimizations\n\
-O : remove assert and __debug__-dependent statements; add .opt-1 before\n\
.pyc extension; also PYTHONOPTIMIZE=x\n\
-OO : do -O changes and also discard docstrings; add .opt-2 before\n\
.pyc extension\n\
-q : don't print version and copyright messages on interactive startup\n\
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
-S : don't imply 'import site' on initialization\n\
Expand Down