# HG changeset patch # Parent ff71c15e48f19e0cf002a932a17f217080d45010 Issue #9694: Change argparse heading "optional arguments" to "options" diff -r ff71c15e48f1 Doc/howto/argparse.rst --- a/Doc/howto/argparse.rst Tue Apr 05 06:20:32 2016 +0000 +++ b/Doc/howto/argparse.rst Tue Apr 05 07:03:46 2016 +0000 @@ -83,7 +83,7 @@ $ python3 prog.py --help usage: prog.py [-h] - optional arguments: + options: -h, --help show this help message and exit $ python3 prog.py --verbose usage: prog.py [-h] @@ -130,7 +130,7 @@ positional arguments: echo - optional arguments: + options: -h, --help show this help message and exit $ python3 prog.py foo foo @@ -172,7 +172,7 @@ positional arguments: echo echo the string you use here - optional arguments: + options: -h, --help show this help message and exit Now, how about doing something even more useful:: @@ -241,7 +241,7 @@ $ python3 prog.py --help usage: prog.py [-h] [--verbosity VERBOSITY] - optional arguments: + options: -h, --help show this help message and exit --verbosity VERBOSITY increase output verbosity @@ -289,7 +289,7 @@ $ python3 prog.py --help usage: prog.py [-h] [--verbose] - optional arguments: + options: -h, --help show this help message and exit --verbose increase output verbosity @@ -332,7 +332,7 @@ $ python3 prog.py --help usage: prog.py [-h] [-v] - optional arguments: + options: -h, --help show this help message and exit -v, --verbose increase output verbosity @@ -440,7 +440,7 @@ positional arguments: square display a square of a given number - optional arguments: + options: -h, --help show this help message and exit -v {0,1,2}, --verbosity {0,1,2} increase output verbosity @@ -489,7 +489,7 @@ positional arguments: square display a square of a given number - optional arguments: + options: -h, --help show this help message and exit -v, --verbosity increase output verbosity $ python3 prog.py 4 -vvv @@ -626,7 +626,7 @@ x the base y the exponent - optional arguments: + options: -h, --help show this help message and exit -v, --verbosity $ python3 prog.py 4 2 -v @@ -750,7 +750,7 @@ x the base y the exponent - optional arguments: + options: -h, --help show this help message and exit -v, --verbose -q, --quiet diff -r ff71c15e48f1 Doc/library/argparse.rst --- a/Doc/library/argparse.rst Tue Apr 05 06:20:32 2016 +0000 +++ b/Doc/library/argparse.rst Tue Apr 05 07:03:46 2016 +0000 @@ -54,7 +54,7 @@ positional arguments: N an integer for the accumulator - optional arguments: + options: -h, --help show this help message and exit --sum sum the integers (default: find the max) @@ -198,14 +198,14 @@ $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help $ cd .. $ python subdir\myprogram.py --help usage: myprogram.py [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help @@ -216,7 +216,7 @@ >>> parser.print_help() usage: myprogram [-h] - optional arguments: + options: -h, --help show this help message and exit Note that the program name, whether determined from ``sys.argv[0]`` or from the @@ -230,7 +230,7 @@ >>> parser.print_help() usage: myprogram [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo of the myprogram program @@ -250,7 +250,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo [FOO] foo help @@ -265,7 +265,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo [FOO] foo help @@ -288,7 +288,7 @@ A foo that bars - optional arguments: + options: -h, --help show this help message and exit By default, the description will be line-wrapped so that it fits within the @@ -310,7 +310,7 @@ A foo that bars - optional arguments: + options: -h, --help show this help message and exit And that's how you'd foo a bar @@ -384,7 +384,7 @@ this description was indented weird but that is okay - optional arguments: + options: -h, --help show this help message and exit likewise for this epilog whose whitespace will be cleaned up and whose words @@ -413,7 +413,7 @@ exactly the way I want it - optional arguments: + options: -h, --help show this help message and exit :class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text, @@ -433,7 +433,7 @@ positional arguments: bar BAR! (default: [1, 2, 3]) - optional arguments: + options: -h, --help show this help message and exit --foo FOO FOO! (default: 42) @@ -452,7 +452,7 @@ positional arguments: float - optional arguments: + options: -h, --help show this help message and exit --foo int @@ -571,7 +571,7 @@ >>> parser.print_help() usage: PROG [-h] [-f FOO] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit -f FOO old foo help --foo FOO new foo help @@ -600,7 +600,7 @@ $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help @@ -613,7 +613,7 @@ >>> parser.print_help() usage: PROG [--foo FOO] - optional arguments: + options: --foo FOO foo help The help option is typically ``-h/--help``. The exception to this is @@ -626,7 +626,7 @@ >>> parser.print_help() usage: PROG [+h] - optional arguments: + options: +h, ++help show this help message and exit @@ -1118,7 +1118,7 @@ positional arguments: bar one of the bars to be frobbled - optional arguments: + options: -h, --help show this help message and exit --foo foo the bars before frobbling @@ -1136,7 +1136,7 @@ positional arguments: bar the bar to frobble (default: 42) - optional arguments: + options: -h, --help show this help message and exit As the help string supports %-formatting, if you want a literal ``%`` to appear @@ -1150,7 +1150,7 @@ >>> parser.print_help() usage: frobble [-h] - optional arguments: + options: -h, --help show this help message and exit @@ -1177,7 +1177,7 @@ positional arguments: bar - optional arguments: + options: -h, --help show this help message and exit --foo FOO @@ -1194,7 +1194,7 @@ positional arguments: XXX - optional arguments: + options: -h, --help show this help message and exit --foo YYY @@ -1212,7 +1212,7 @@ >>> parser.print_help() usage: PROG [-h] [-x X X] [--foo bar baz] - optional arguments: + options: -h, --help show this help message and exit -x X X --foo bar baz @@ -1605,7 +1605,7 @@ a a help b b help - optional arguments: + options: -h, --help show this help message and exit --foo foo help @@ -1615,13 +1615,13 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit >>> parser.parse_args(['b', '--help']) usage: PROG b [-h] [--baz {X,Y,Z}] - optional arguments: + options: -h, --help show this help message and exit --baz {X,Y,Z} baz help @@ -1638,7 +1638,7 @@ >>> parser.parse_args(['-h']) usage: [-h] {foo,bar} ... - optional arguments: + options: -h, --help show this help message and exit subcommands: @@ -1747,7 +1747,7 @@ .. method:: ArgumentParser.add_argument_group(title=None, description=None) By default, :class:`ArgumentParser` groups command-line arguments into - "positional arguments" and "optional arguments" when displaying help + "positional arguments" and "options" when displaying help messages. When there is a better conceptual grouping of arguments than this default one, appropriate groups can be created using the :meth:`add_argument_group` method:: @@ -1790,7 +1790,10 @@ --bar BAR bar help Note that any arguments not in your user-defined groups will end up back - in the usual "positional arguments" and "optional arguments" sections. + in the usual "positional arguments" and "options" sections. + +.. versionchanged:: 3.6 + The default "options" group was previously called "optional arguments". Mutual exclusion diff -r ff71c15e48f1 Doc/whatsnew/3.6.rst --- a/Doc/whatsnew/3.6.rst Tue Apr 05 06:20:32 2016 +0000 +++ b/Doc/whatsnew/3.6.rst Tue Apr 05 07:03:46 2016 +0000 @@ -486,6 +486,10 @@ * :func:`spwd.getspnam` now raises a :exc:`PermissionError` instead of :exc:`KeyError` if the user doesn't have privileges. +* The :mod:`argparse` module now groups non-positional arguments under + the heading "options", rather than the previous heading + "optional arguments". + Changes in the C API -------------------- diff -r ff71c15e48f1 Lib/argparse.py --- a/Lib/argparse.py Tue Apr 05 06:20:32 2016 +0000 +++ b/Lib/argparse.py Tue Apr 05 07:03:46 2016 +0000 @@ -1631,7 +1631,7 @@ add_group = self.add_argument_group self._positionals = add_group(_('positional arguments')) - self._optionals = add_group(_('optional arguments')) + self._optionals = add_group(_('options')) self._subparsers = None # register types diff -r ff71c15e48f1 Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Tue Apr 05 06:20:32 2016 +0000 +++ b/Lib/test/test_argparse.py Tue Apr 05 07:03:46 2016 +0000 @@ -1919,7 +1919,7 @@ bar bar help {1,2,3} command help - optional arguments: + options: -h, --help show this help message and exit --foo foo help ''')) @@ -1938,7 +1938,7 @@ bar bar help {1,2,3} command help - optional arguments: + options: -h, --help show this help message and exit ++foo foo help ''')) @@ -1957,7 +1957,7 @@ bar bar help {1,2,3} command help - optional arguments: + options: +h, ++help show this help message and exit ++foo foo help ''')) @@ -1978,7 +1978,7 @@ 2 2 help 3 3 help - optional arguments: + options: -h, --help show this help message and exit --foo foo help ''')) @@ -2003,7 +2003,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo foo help @@ -2027,7 +2027,7 @@ positional arguments: {a,b,c} x help - optional arguments: + options: -h, --help show this help message and exit -w W w help ''')) @@ -2041,7 +2041,7 @@ positional arguments: z z help - optional arguments: + options: -h, --help show this help message and exit -y {1,2,3} y help ''')) @@ -2073,7 +2073,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo foo help @@ -2261,7 +2261,7 @@ a z - optional arguments: + options: -h, --help show this help message and exit -b B --w W @@ -2291,7 +2291,7 @@ self.assertEqual(parser_help, textwrap.dedent('''\ usage: {}{}[-h] [-w W] [-x X] [-y Y | -z Z] - optional arguments: + options: -h, --help show this help message and exit -y Y -z Z @@ -2336,7 +2336,7 @@ expected = '''\ usage: PROG [-h] [--foo | --bar] [--soup | --nuts] - optional arguments: + options: -h, --help show this help message and exit --foo --bar @@ -2421,7 +2421,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit --bar BAR bar help --baz [BAZ] baz help @@ -2462,7 +2462,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit --abcde ABCDE abcde help --fghij FGHIJ fghij help @@ -2498,7 +2498,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit -y y help ''' @@ -2535,7 +2535,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit ''' @@ -2578,7 +2578,7 @@ positional arguments: badger BADGER - optional arguments: + options: -h, --help show this help message and exit --foo FOO --spam SPAM SPAM @@ -2617,7 +2617,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit -x x help -a a help @@ -2656,7 +2656,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit Titled group: @@ -2701,7 +2701,7 @@ x x help a a help - optional arguments: + options: -h, --help show this help message and exit -y y help -b b help @@ -3010,7 +3010,7 @@ foo FOO HELP bar BAR HELP - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit -x X HELP @@ -3055,7 +3055,7 @@ bar BAR HELP - optional arguments: + options: -h, --help show this help @@ -3105,7 +3105,7 @@ foo FOO HELP bar BAR HELP - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit -x X HELP @@ -3146,7 +3146,7 @@ ekiekiekifekang EKI HELP bar BAR HELP - optional arguments: + options: -h, --help show this help message and exit -x X HELP --y Y Y HELP @@ -3193,7 +3193,7 @@ positional arguments: yyy normal y help - optional arguments: + options: -h, --help show this help message and exit -x XX oddly formatted -x help @@ -3233,7 +3233,7 @@ YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH - optional arguments: + options: -h, --help show this help message and exit -x XX XHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH \ HXXHH HXXHH @@ -3276,7 +3276,7 @@ YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit -x XXXXXXXXXXXXXXXXXXXXXXXXX @@ -3331,7 +3331,7 @@ b b c c - optional arguments: + options: -h, --help show this help message and exit -w W [W ...] w -x [X [X ...]] x @@ -3397,7 +3397,7 @@ a b - optional arguments: + options: -h, --help show this help message and exit -w W -x X @@ -3431,7 +3431,7 @@ a b - optional arguments: + options: -h, --help show this help message and exit -w WWWWWWWWWWWWWWWWWWWWWWWWW -x XXXXXXXXXXXXXXXXXXXXXXXXX @@ -3494,7 +3494,7 @@ b c - optional arguments: + options: -h, --help show this help message and exit -w WWWWWWWWWWWWWWWWWWWWWWWWW -x XXXXXXXXXXXXXXXXXXXXXXXXX @@ -3529,7 +3529,7 @@ bbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc - optional arguments: + options: -h, --help show this help message and exit -x X -y Y @@ -3565,7 +3565,7 @@ bbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc - optional arguments: + options: -h, --help show this help message and exit -x XXXXXXXXXXXXXXXXXXXXXXXXX -y YYYYYYYYYYYYYYYYYYYYYYYYY @@ -3591,7 +3591,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit -x XXXXXXXXXXXXXXXXXXXXXXXXX -y YYYYYYYYYYYYYYYYYYYYYYYYY @@ -3656,7 +3656,7 @@ spam spam PROG None badger badger PROG 0.5 - optional arguments: + options: -h, --help show this help message and exit -x X x PROG None int % -y y PROG 42 XXX @@ -3681,7 +3681,7 @@ ''') help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit ''' version = '' @@ -3713,7 +3713,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3760,7 +3760,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3781,7 +3781,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3801,7 +3801,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3822,7 +3822,7 @@ ''' help = usage + '''\ - optional arguments: + options: ^^foo foo help ;b BAR, ;;bar BAR bar help ''' @@ -3846,7 +3846,7 @@ positional arguments: spam spam help - optional arguments: + options: --foo FOO foo help ''' version = '' @@ -3869,7 +3869,7 @@ positional arguments: spam - optional arguments: + options: -h, --help show this help message and exit --foo FOO ''' @@ -3893,7 +3893,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit -w W1 [W2 ...] w -x [X1 [X2 ...]] x @@ -3937,7 +3937,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help should also appear as given here @@ -3986,7 +3986,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help should not retain this odd formatting @@ -4028,7 +4028,7 @@ spam spam help badger badger help (default: wooden) - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help - oh and by the way, None --bar bar help (default: False) @@ -4053,7 +4053,7 @@ description - optional arguments: + options: -h, --help show this help message and exit -V, --version show program's version number and exit ''' @@ -4079,7 +4079,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -4105,7 +4105,7 @@ positional arguments: {a,b,c,d,e} - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit ''' @@ -4146,7 +4146,7 @@ d d subcommand help e e subcommand help - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit ''' @@ -4179,7 +4179,7 @@ positional arguments: int - optional arguments: + options: -h, --help show this help message and exit -b custom_type -c SOME FLOAT @@ -4371,7 +4371,7 @@ self.assertEqual(parser.format_help(), textwrap.dedent('''\ usage: PROG [-h] [-x X] - optional arguments: + options: -h, --help show this help message and exit -x X NEW X ''')) @@ -4381,7 +4381,7 @@ self.assertEqual(parser.format_help(), textwrap.dedent('''\ usage: PROG [-h] [-x X] [--spam NEW_SPAM] - optional arguments: + options: -h, --help show this help message and exit -x X NEW X --spam NEW_SPAM diff -r ff71c15e48f1 Misc/NEWS --- a/Misc/NEWS Tue Apr 05 06:20:32 2016 +0000 +++ b/Misc/NEWS Tue Apr 05 07:03:46 2016 +0000 @@ -237,6 +237,9 @@ Library ------- +- Issue #9694: Change argparse "optional arguments" group heading to + "options". + - Issue #23735: Handle terminal resizing with Readline 6.3+ by installing our own SIGWINCH handler. Patch by Eric Price.

AltStyle によって変換されたページ (->オリジナル) /