Skip to content

Commit 41b223d

Browse files
authored
bpo-9694: Fix misleading phrase "optional arguments" (GH-23858)
1 parent bfda4f5 commit 41b223d

File tree

5 files changed

+98
-95
lines changed

5 files changed

+98
-95
lines changed

Doc/howto/argparse.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Following is a result of running the code:
8383
$ python3 prog.py --help
8484
usage: prog.py [-h]
8585
86-
optional arguments:
86+
options:
8787
-h, --help show this help message and exit
8888
$ python3 prog.py --verbose
8989
usage: prog.py [-h]
@@ -130,7 +130,7 @@ And running the code:
130130
positional arguments:
131131
echo
132132
133-
optional arguments:
133+
options:
134134
-h, --help show this help message and exit
135135
$ python3 prog.py foo
136136
foo
@@ -172,7 +172,7 @@ And we get:
172172
positional arguments:
173173
echo echo the string you use here
174174
175-
optional arguments:
175+
options:
176176
-h, --help show this help message and exit
177177
178178
Now, how about doing something even more useful::
@@ -241,7 +241,7 @@ And the output:
241241
$ python3 prog.py --help
242242
usage: prog.py [-h] [--verbosity VERBOSITY]
243243
244-
optional arguments:
244+
options:
245245
-h, --help show this help message and exit
246246
--verbosity VERBOSITY
247247
increase output verbosity
@@ -289,7 +289,7 @@ And the output:
289289
$ python3 prog.py --help
290290
usage: prog.py [-h] [--verbose]
291291
292-
optional arguments:
292+
options:
293293
-h, --help show this help message and exit
294294
--verbose increase output verbosity
295295
@@ -332,7 +332,7 @@ And here goes:
332332
$ python3 prog.py --help
333333
usage: prog.py [-h] [-v]
334334
335-
optional arguments:
335+
options:
336336
-h, --help show this help message and exit
337337
-v, --verbose increase output verbosity
338338
@@ -440,7 +440,7 @@ And the output:
440440
positional arguments:
441441
square display a square of a given number
442442
443-
optional arguments:
443+
options:
444444
-h, --help show this help message and exit
445445
-v {0,1,2}, --verbosity {0,1,2}
446446
increase output verbosity
@@ -468,7 +468,8 @@ verbosity argument (check the output of ``python --help``)::
468468
print(answer)
469469

470470
We have introduced another action, "count",
471-
to count the number of occurrences of a specific optional arguments:
471+
to count the number of occurrences of specific options.
472+
472473

473474
.. code-block:: shell-session
474475
@@ -489,7 +490,7 @@ to count the number of occurrences of a specific optional arguments:
489490
positional arguments:
490491
square display a square of a given number
491492
492-
optional arguments:
493+
options:
493494
-h, --help show this help message and exit
494495
-v, --verbosity increase output verbosity
495496
$ python3 prog.py 4 -vvv
@@ -626,7 +627,7 @@ Output:
626627
x the base
627628
y the exponent
628629
629-
optional arguments:
630+
options:
630631
-h, --help show this help message and exit
631632
-v, --verbosity
632633
$ python3 prog.py 4 2 -v
@@ -750,7 +751,7 @@ but not both at the same time:
750751
x the base
751752
y the exponent
752753
753-
optional arguments:
754+
options:
754755
-h, --help show this help message and exit
755756
-v, --verbose
756757
-q, --quiet

Doc/library/argparse.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ be run at the command line and provides useful help messages:
5757
positional arguments:
5858
N an integer for the accumulator
5959
60-
optional arguments:
60+
options:
6161
-h, --help show this help message and exit
6262
--sum sum the integers (default: find the max)
6363
@@ -217,14 +217,14 @@ The help for this program will display ``myprogram.py`` as the program name
217217
$ python myprogram.py --help
218218
usage: myprogram.py [-h] [--foo FOO]
219219
220-
optional arguments:
220+
options:
221221
-h, --help show this help message and exit
222222
--foo FOO foo help
223223
$ cd ..
224224
$ python subdir/myprogram.py --help
225225
usage: myprogram.py [-h] [--foo FOO]
226226
227-
optional arguments:
227+
options:
228228
-h, --help show this help message and exit
229229
--foo FOO foo help
230230
@@ -235,7 +235,7 @@ To change this default behavior, another value can be supplied using the
235235
>>> parser.print_help()
236236
usage: myprogram [-h]
237237

238-
optional arguments:
238+
options:
239239
-h, --help show this help message and exit
240240

241241
Note that the program name, whether determined from ``sys.argv[0]`` or from the
@@ -249,7 +249,7 @@ specifier.
249249
>>> parser.print_help()
250250
usage: myprogram [-h] [--foo FOO]
251251

252-
optional arguments:
252+
options:
253253
-h, --help show this help message and exit
254254
--foo FOO foo of the myprogram program
255255

@@ -269,7 +269,7 @@ arguments it contains::
269269
positional arguments:
270270
bar bar help
271271

272-
optional arguments:
272+
options:
273273
-h, --help show this help message and exit
274274
--foo [FOO] foo help
275275

@@ -284,7 +284,7 @@ The default message can be overridden with the ``usage=`` keyword argument::
284284
positional arguments:
285285
bar bar help
286286

287-
optional arguments:
287+
options:
288288
-h, --help show this help message and exit
289289
--foo [FOO] foo help
290290

@@ -307,7 +307,7 @@ various arguments::
307307

308308
A foo that bars
309309

310-
optional arguments:
310+
options:
311311
-h, --help show this help message and exit
312312

313313
By default, the description will be line-wrapped so that it fits within the
@@ -329,7 +329,7 @@ argument to :class:`ArgumentParser`::
329329

330330
A foo that bars
331331

332-
optional arguments:
332+
options:
333333
-h, --help show this help message and exit
334334

335335
And that's how you'd foo a bar
@@ -403,7 +403,7 @@ epilog_ texts in command-line help messages::
403403

404404
this description was indented weird but that is okay
405405

406-
optional arguments:
406+
options:
407407
-h, --help show this help message and exit
408408

409409
likewise for this epilog whose whitespace will be cleaned up and whose words
@@ -432,7 +432,7 @@ should not be line-wrapped::
432432
exactly the way
433433
I want it
434434

435-
optional arguments:
435+
options:
436436
-h, --help show this help message and exit
437437

438438
:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text,
@@ -454,7 +454,7 @@ default values to each of the argument help messages::
454454
positional arguments:
455455
bar BAR! (default: [1, 2, 3])
456456

457-
optional arguments:
457+
options:
458458
-h, --help show this help message and exit
459459
--foo FOO FOO! (default: 42)
460460

@@ -473,7 +473,7 @@ as the regular formatter does)::
473473
positional arguments:
474474
float
475475

476-
optional arguments:
476+
options:
477477
-h, --help show this help message and exit
478478
--foo int
479479

@@ -592,7 +592,7 @@ older arguments with the same option string. To get this behavior, the value
592592
>>> parser.print_help()
593593
usage: PROG [-h] [-f FOO] [--foo FOO]
594594

595-
optional arguments:
595+
options:
596596
-h, --help show this help message and exit
597597
-f FOO old foo help
598598
--foo FOO new foo help
@@ -623,7 +623,7 @@ help will be printed:
623623
$ python myprogram.py --help
624624
usage: myprogram.py [-h] [--foo FOO]
625625
626-
optional arguments:
626+
options:
627627
-h, --help show this help message and exit
628628
--foo FOO foo help
629629
@@ -636,7 +636,7 @@ This can be achieved by passing ``False`` as the ``add_help=`` argument to
636636
>>> parser.print_help()
637637
usage: PROG [--foo FOO]
638638

639-
optional arguments:
639+
options:
640640
--foo FOO foo help
641641

642642
The help option is typically ``-h/--help``. The exception to this is
@@ -649,7 +649,7 @@ the help options::
649649
>>> parser.print_help()
650650
usage: PROG [+h]
651651

652-
optional arguments:
652+
options:
653653
+h, ++help show this help message and exit
654654

655655

@@ -1203,7 +1203,7 @@ argument::
12031203
positional arguments:
12041204
bar one of the bars to be frobbled
12051205

1206-
optional arguments:
1206+
options:
12071207
-h, --help show this help message and exit
12081208
--foo foo the bars before frobbling
12091209

@@ -1221,7 +1221,7 @@ specifiers include the program name, ``%(prog)s`` and most keyword arguments to
12211221
positional arguments:
12221222
bar the bar to frobble (default: 42)
12231223

1224-
optional arguments:
1224+
options:
12251225
-h, --help show this help message and exit
12261226

12271227
As the help string supports %-formatting, if you want a literal ``%`` to appear
@@ -1235,7 +1235,7 @@ setting the ``help`` value to ``argparse.SUPPRESS``::
12351235
>>> parser.print_help()
12361236
usage: frobble [-h]
12371237

1238-
optional arguments:
1238+
options:
12391239
-h, --help show this help message and exit
12401240

12411241

@@ -1262,7 +1262,7 @@ will be referred to as ``FOO``. An example::
12621262
positional arguments:
12631263
bar
12641264

1265-
optional arguments:
1265+
options:
12661266
-h, --help show this help message and exit
12671267
--foo FOO
12681268

@@ -1279,7 +1279,7 @@ An alternative name can be specified with ``metavar``::
12791279
positional arguments:
12801280
XXX
12811281

1282-
optional arguments:
1282+
options:
12831283
-h, --help show this help message and exit
12841284
--foo YYY
12851285

@@ -1297,7 +1297,7 @@ arguments::
12971297
>>> parser.print_help()
12981298
usage: PROG [-h] [-x X X] [--foo bar baz]
12991299

1300-
optional arguments:
1300+
options:
13011301
-h, --help show this help message and exit
13021302
-x X X
13031303
--foo bar baz
@@ -1701,7 +1701,7 @@ Sub-commands
17011701
a a help
17021702
b b help
17031703

1704-
optional arguments:
1704+
options:
17051705
-h, --help show this help message and exit
17061706
--foo foo help
17071707

@@ -1711,13 +1711,13 @@ Sub-commands
17111711
positional arguments:
17121712
bar bar help
17131713

1714-
optional arguments:
1714+
options:
17151715
-h, --help show this help message and exit
17161716

17171717
>>> parser.parse_args(['b', '--help'])
17181718
usage: PROG b [-h] [--baz {X,Y,Z}]
17191719

1720-
optional arguments:
1720+
options:
17211721
-h, --help show this help message and exit
17221722
--baz {X,Y,Z} baz help
17231723

@@ -1734,7 +1734,7 @@ Sub-commands
17341734
>>> parser.parse_args(['-h'])
17351735
usage: [-h] {foo,bar} ...
17361736

1737-
optional arguments:
1737+
options:
17381738
-h, --help show this help message and exit
17391739

17401740
subcommands:

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ def __init__(self,
17191719

17201720
add_group = self.add_argument_group
17211721
self._positionals = add_group(_('positional arguments'))
1722-
self._optionals = add_group(_('optional arguments'))
1722+
self._optionals = add_group(_('options'))
17231723
self._subparsers = None
17241724

17251725
# register types

0 commit comments

Comments
 (0)