Skip to content

Commit fc9471a

Browse files
bpo-17232: Clarify docs for -O and -OO command line options (GH-5839)
The 'optimization' is for space in the executable file, not for run time. (cherry picked from commit 186b606) Co-authored-by: Cheryl Sabella <[email protected]>
1 parent aab2258 commit fc9471a

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

Doc/using/cmdline.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,23 @@ Miscellaneous options
246246

247247
.. cmdoption:: -O
248248

249-
Turn on basic optimizations. See also :envvar:`PYTHONOPTIMIZE`.
249+
Remove assert statements and any code conditional on the value of
250+
:const:`__debug__`. Augment the filename for compiled
251+
(:term:`bytecode`) files by adding ``.opt-1`` before the ``.pyc``
252+
extension (see :pep:`488`). See also :envvar:`PYTHONOPTIMIZE`.
253+
254+
.. versionchanged:: 3.5
255+
Modify ``.pyc`` filenames according to :pep:`488`.
250256

251257

252258
.. cmdoption:: -OO
253259

254-
Discard docstrings in addition to the :option:`-O` optimizations.
260+
Do :option:`-O` and also discard docstrings. Augment the filename
261+
for compiled (:term:`bytecode`) files by adding ``.opt-2`` before the
262+
``.pyc`` extension (see :pep:`488`).
263+
264+
.. versionchanged:: 3.5
265+
Modify ``.pyc`` filenames according to :pep:`488`.
255266

256267

257268
.. cmdoption:: -q
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify docs for -O and -OO. Patch by Terry Reedy.

Misc/python.man

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,13 @@ for the named module and runs the corresponding
156156
file as a script.
157157
.TP
158158
.B \-O
159-
Turn on basic optimizations. Given twice, causes docstrings to be discarded.
159+
Remove assert statements and any code conditional on the value of
160+
__debug__; augment the filename for compiled (bytecode) files by
161+
adding .opt-1 before the .pyc extension.
160162
.TP
161163
.B \-OO
162-
Discard docstrings in addition to the \fB-O\fP optimizations.
164+
Do \fB-O\fP and also discard docstrings; change the filename for
165+
compiled (bytecode) files by adding .opt-2 before the .pyc extension.
163166
.TP
164167
.B \-q
165168
Do not print the version and copyright messages. These messages are

Modules/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ static const char usage_2[] = "\
6464
if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
6565
-I : isolate Python from the user's environment (implies -E and -s)\n\
6666
-m mod : run library module as a script (terminates option list)\n\
67-
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\
68-
-OO : remove doc-strings in addition to the -O optimizations\n\
67+
-O : remove assert and __debug__-dependent statements; add .opt-1 before\n\
68+
.pyc extension; also PYTHONOPTIMIZE=x\n\
69+
-OO : do -O changes and also discard docstrings; add .opt-2 before\n\
70+
.pyc extension\n\
6971
-q : don't print version and copyright messages on interactive startup\n\
7072
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\
7173
-S : don't imply 'import site' on initialization\n\

0 commit comments

Comments
 (0)