From bddc7487f3ba4c4c7215a6dadfff09c791d30581 Mon Sep 17 00:00:00 2001 From: Tadek Kijkowski Date: Tue, 19 Jan 2021 21:09:34 +0100 Subject: [PATCH 1/7] argparse: mixing optional and positional Allow positional parameter with nargs='*' to match more than once without reordering parameters. Restoration of old patch from bpo-14191. --- Lib/argparse.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 8a12dea7668799..f32f60433d439b 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1696,7 +1696,8 @@ def __init__(self, conflict_handler='error', add_help=True, allow_abbrev=True, - exit_on_error=True): + exit_on_error=True, + greedy_star=False): superinit = super(ArgumentParser, self).__init__ superinit(description=description, @@ -1716,6 +1717,7 @@ def __init__(self, self.add_help = add_help self.allow_abbrev = allow_abbrev self.exit_on_error = exit_on_error + self.greedy_star = greedy_star add_group = self.add_argument_group self._positionals = add_group(_('positional arguments')) @@ -2010,17 +2012,22 @@ def consume_positionals(start_index): match_partial = self._match_arguments_partial selected_pattern = arg_strings_pattern[start_index:] arg_counts = match_partial(positionals, selected_pattern) + action_index = 0 # slice off the appropriate arg strings for each Positional # and add the Positional and its args to the list - for action, arg_count in zip(positionals, arg_counts): + for arg_count in arg_counts: + action = positionals[action_index] args = arg_strings[start_index: start_index + arg_count] start_index += arg_count take_action(action, args) + # positional action is '*', never remove it from list + if not self.greedy_star or action.nargs != ZERO_OR_MORE: + action_index += 1 # slice off the Positionals that we just parsed and return the # index at which the Positionals' string args stopped - positionals[:] = positionals[len(arg_counts):] + positionals[:] = positionals[action_index:] return start_index # consume Positionals and Optionals alternately, until we have From b8eeb22caaee827c3cbf5b2d11b316575d11e7be Mon Sep 17 00:00:00 2001 From: Tadek Kijkowski Date: Mon, 25 Jan 2021 20:58:27 +0100 Subject: [PATCH 2/7] bpo-42973: argparse: mixing optional and positional New parameter to ArgumentParser constructor - 'greedy' makes positional parameters consume multiple groups of command-line arguments. Added tests and docs. --- Doc/library/argparse.rst | 92 ++++++++++++++++++++++++++++++++++++++- Lib/argparse.py | 9 ++-- Lib/test/test_argparse.py | 19 ++++++++ 3 files changed, 115 insertions(+), 5 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 80e0f013df09e5..3198d510ac9823 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -142,7 +142,8 @@ ArgumentParser objects formatter_class=argparse.HelpFormatter, \ prefix_chars='-', fromfile_prefix_chars=None, \ argument_default=None, conflict_handler='error', \ - add_help=True, allow_abbrev=True, exit_on_error=True) + add_help=True, allow_abbrev=True, exit_on_error=True, \ + greedy=False) Create a new :class:`ArgumentParser` object. All parameters should be passed as keyword arguments. Each parameter has its own more detailed description @@ -182,6 +183,10 @@ ArgumentParser objects * exit_on_error_ - Determines whether or not ArgumentParser exits with error info when an error occurs. (default: ``True``) + * greedy_ - Allows positional arguments with ``nargs='*'`` to consume + multiple groups of command-line arguments, interspersed with optional + arguments. (default: ``False``) + .. versionchanged:: 3.5 *allow_abbrev* parameter was added. @@ -192,6 +197,9 @@ ArgumentParser objects .. versionchanged:: 3.9 *exit_on_error* parameter was added. + .. versionchanged:: 3.10 + *greedy* parameter was added. + The following sections describe how each of these are used. @@ -675,6 +683,86 @@ If the user would like catch errors manually, the feature can be enable by setti .. versionadded:: 3.9 +greedy +^^^^^^ + + +By default, positional argument with ``nargs='*'`` will only consume one group +of command-line arguments, up to first encountered optional argument:: + + >>> parser = argparse.ArgumentParser() + >>> parser.add_argument('--foo', action='store_true') + >>> parser.add_argument('bar', nargs='*') + >>> parser.parse_args('arg1 arg2 --foo arg3 arg4'.split()) + usage: [-h] [--foo] [bar ...] + : error: unrecognized arguments: arg3 arg4 + +In some cases it may be desirable to collect unspecified number of positional +arguments and still allow to intersperse them with optional arguments. This can +be achieved by setting ``greedy`` to ``True``:: + + >>> parser = argparse.ArgumentParser(greedy=True) + >>> parser.add_argument('--foo', action='store_true') + >>> parser.add_argument('bar', nargs='*', action='extend') + >>> parser.parse_args('arg1 arg2 --foo arg3 arg4'.split()) + Namespace(foo=True, bar=['arg1', 'arg2', 'arg3', 'arg4']) + +Note that since action associated with the positional argument is executed for +each consecutive group of command-line arguments, using default ``store`` action +will likely not give expected results - it would just contain the last group of +arguments (``arg3`` and ``arg4`` in the example above). + +Conversely, here is an example which requires ``greedy`` not set:: + + >>> parser = argparse.ArgumentParser() + >>> parser.add_argument('foo', nargs='*') + >>> parser.add_argument('last') + >>> parser.parse_args('first second third'.split()) + Namespace(foo=['first', 'second'], last='third') + +If ``greedy`` was set in the example above, argument parsing would always fail, +because argument ``last`` could never match command-line argument. +As a rule, if ``greedy`` is set, positional argument with ``nargs='*'``, if +present, must be the last positional argument. + +Example below combines ``greedy`` with custom :ref:`Action class` +to allow providing additional properties for each positional argument:: + + import argparse + + DEFAULT_COLOR="plain" + + class AddFruitAction(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + for fruit in values: + namespace.fruits.append({'name': fruit, 'color': namespace.color}) + namespace.color = DEFAULT_COLOR + + def show_fruits(fruits): + for fruit in fruits: + print(f"{fruit['color']} {fruit['name']}") + + parser = argparse.ArgumentParser(greedy=True) + parser.add_argument('--color', default=DEFAULT_COLOR) + parser.add_argument('fruits', nargs='*', action=AddFruitAction, default=[]) + args = parser.parse_args() + show_fruits(args.fruits) + + +If the code above was saved to file ``fruits.py``, it could be executed like +this: + +.. code-block:: shell-session + + $ python fruits.py --color green apple pear kiwi --color brown banana + green apple + plain pear + plain kiwi + yellow banana + +.. versionadded:: 3.10 + + The add_argument() method ------------------------- @@ -1342,6 +1430,8 @@ behavior:: >>> parser.parse_args('--foo XXX'.split()) Namespace(bar='XXX') +.. _action-classes: + Action classes ^^^^^^^^^^^^^^ diff --git a/Lib/argparse.py b/Lib/argparse.py index f32f60433d439b..13e641146b4121 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1697,7 +1697,7 @@ def __init__(self, add_help=True, allow_abbrev=True, exit_on_error=True, - greedy_star=False): + greedy=False): superinit = super(ArgumentParser, self).__init__ superinit(description=description, @@ -1717,7 +1717,7 @@ def __init__(self, self.add_help = add_help self.allow_abbrev = allow_abbrev self.exit_on_error = exit_on_error - self.greedy_star = greedy_star + self.greedy = greedy add_group = self.add_argument_group self._positionals = add_group(_('positional arguments')) @@ -2021,8 +2021,9 @@ def consume_positionals(start_index): args = arg_strings[start_index: start_index + arg_count] start_index += arg_count take_action(action, args) - # positional action is '*', never remove it from list - if not self.greedy_star or action.nargs != ZERO_OR_MORE: + # if greedy is on and positional action nargs is '*', + # never remove it from actions list + if not self.greedy or action.nargs != ZERO_OR_MORE: action_index += 1 # slice off the Positionals that we just parsed and return the diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index ec9711e4f6a472..8621d8999a8cc7 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5012,6 +5012,25 @@ def test_mixed(self): self.assertEqual(NS(v=3, spam=True, badger="B"), args) self.assertEqual(["C", "--foo", "4"], extras) + def test_nongreedy(self): + parser = argparse.ArgumentParser() + parser.add_argument('first', nargs='*', action='extend') + parser.add_argument('second') + + argv = ['arg1', 'arg2', 'arg3'] + args = parser.parse_args(argv) + self.assertEqual(NS(first=['arg1', 'arg2'], second='arg3'), args) + + def test_greedy(self): + parser = argparse.ArgumentParser(greedy=True) + parser.add_argument('--foo', action='store') + parser.add_argument('first', nargs='*', action='extend') + + argv = ['arg1', 'arg2', '--foo', 'bar', 'arg3', 'arg4'] + args = parser.parse_args(argv) + self.assertEqual(NS(foo='bar', + first=['arg1', 'arg2', 'arg3', 'arg4']), args) + # =========================== # parse_intermixed_args tests # =========================== From 3a5b752d5b4cbdc80dc30f7c9239afd63db08323 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 25 Jan 2021 20:17:20 +0000 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst diff --git a/Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst b/Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst new file mode 100644 index 00000000000000..fad719823850c8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst @@ -0,0 +1 @@ +Added new parameter ``greedy`` to :class:`ArgumentParser` constructor which allows positional arguments with ``nargs='*'`` to match positional arguments interspersed with optional arguments. \ No newline at end of file From d0108e77b23d6aea5465cc54df2fd6441a396e23 Mon Sep 17 00:00:00 2001 From: Tadek Kijkowski Date: Tue, 26 Jan 2021 00:49:37 +0100 Subject: [PATCH 4/7] bpo-42973: argparse: mixing optional and positional Fixed silly mistake in example in docs. --- Doc/library/argparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 3198d510ac9823..e43d33f7b09162 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -754,7 +754,7 @@ this: .. code-block:: shell-session - $ python fruits.py --color green apple pear kiwi --color brown banana + $ python fruits.py --color green apple pear kiwi --color yellow banana green apple plain pear plain kiwi From c21d3b85c5d97ee30692f047045ddd926d60bc43 Mon Sep 17 00:00:00 2001 From: Tadek Kijkowski Date: Wed, 27 Jan 2021 11:42:59 +0100 Subject: [PATCH 5/7] bpo-42973: argparse: mixing optional and positional Removed 'greedy' parameter, added nargs='**' --- Doc/library/argparse.rst | 109 ++++-------------- Lib/argparse.py | 26 +++-- Lib/test/test_argparse.py | 4 +- .../2021-01-25-20-17-18.bpo-42973._HL64W.rst | 1 - 4 files changed, 41 insertions(+), 99 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index e43d33f7b09162..c25ca5912d0e8e 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -183,10 +183,6 @@ ArgumentParser objects * exit_on_error_ - Determines whether or not ArgumentParser exits with error info when an error occurs. (default: ``True``) - * greedy_ - Allows positional arguments with ``nargs='*'`` to consume - multiple groups of command-line arguments, interspersed with optional - arguments. (default: ``False``) - .. versionchanged:: 3.5 *allow_abbrev* parameter was added. @@ -197,9 +193,6 @@ ArgumentParser objects .. versionchanged:: 3.9 *exit_on_error* parameter was added. - .. versionchanged:: 3.10 - *greedy* parameter was added. - The following sections describe how each of these are used. @@ -683,86 +676,6 @@ If the user would like catch errors manually, the feature can be enable by setti .. versionadded:: 3.9 -greedy -^^^^^^ - - -By default, positional argument with ``nargs='*'`` will only consume one group -of command-line arguments, up to first encountered optional argument:: - - >>> parser = argparse.ArgumentParser() - >>> parser.add_argument('--foo', action='store_true') - >>> parser.add_argument('bar', nargs='*') - >>> parser.parse_args('arg1 arg2 --foo arg3 arg4'.split()) - usage: [-h] [--foo] [bar ...] - : error: unrecognized arguments: arg3 arg4 - -In some cases it may be desirable to collect unspecified number of positional -arguments and still allow to intersperse them with optional arguments. This can -be achieved by setting ``greedy`` to ``True``:: - - >>> parser = argparse.ArgumentParser(greedy=True) - >>> parser.add_argument('--foo', action='store_true') - >>> parser.add_argument('bar', nargs='*', action='extend') - >>> parser.parse_args('arg1 arg2 --foo arg3 arg4'.split()) - Namespace(foo=True, bar=['arg1', 'arg2', 'arg3', 'arg4']) - -Note that since action associated with the positional argument is executed for -each consecutive group of command-line arguments, using default ``store`` action -will likely not give expected results - it would just contain the last group of -arguments (``arg3`` and ``arg4`` in the example above). - -Conversely, here is an example which requires ``greedy`` not set:: - - >>> parser = argparse.ArgumentParser() - >>> parser.add_argument('foo', nargs='*') - >>> parser.add_argument('last') - >>> parser.parse_args('first second third'.split()) - Namespace(foo=['first', 'second'], last='third') - -If ``greedy`` was set in the example above, argument parsing would always fail, -because argument ``last`` could never match command-line argument. -As a rule, if ``greedy`` is set, positional argument with ``nargs='*'``, if -present, must be the last positional argument. - -Example below combines ``greedy`` with custom :ref:`Action class` -to allow providing additional properties for each positional argument:: - - import argparse - - DEFAULT_COLOR="plain" - - class AddFruitAction(argparse.Action): - def __call__(self, parser, namespace, values, option_string=None): - for fruit in values: - namespace.fruits.append({'name': fruit, 'color': namespace.color}) - namespace.color = DEFAULT_COLOR - - def show_fruits(fruits): - for fruit in fruits: - print(f"{fruit['color']} {fruit['name']}") - - parser = argparse.ArgumentParser(greedy=True) - parser.add_argument('--color', default=DEFAULT_COLOR) - parser.add_argument('fruits', nargs='*', action=AddFruitAction, default=[]) - args = parser.parse_args() - show_fruits(args.fruits) - - -If the code above was saved to file ``fruits.py``, it could be executed like -this: - -.. code-block:: shell-session - - $ python fruits.py --color green apple pear kiwi --color yellow banana - green apple - plain pear - plain kiwi - yellow banana - -.. versionadded:: 3.10 - - The add_argument() method ------------------------- @@ -1049,6 +962,28 @@ values are: usage: PROG [-h] foo [foo ...] PROG: error: the following arguments are required: foo +.. index:: single: **; in argparse module + +* ``'**'``. This value is only valid for positional arguments. Like ``'*'``, + all command-line args are gathered into a list. In contrast to ``'*'``, + all arguments are consumed, even if they are interspersed with optional + arguments. For example:: + + >>> parser = argparse.ArgumentParser() + >>> parser.add_argument('--foo', action='store_true') + >>> parser.add_argument('bar', nargs='**', action='extend') + >>> parser.parse_args('arg1 arg2 --foo arg3 arg4'.split()) + Namespace(foo=True, bar=['arg1', 'arg2', 'arg3', 'arg4']) + + Note that the ``action`` associated with the positional argument is executed + for each group of command-line args separated by optional args, so using the + default ``'store'`` action will not give expected results. In the example + above, if ``action`` was ``'store'``, ``bar`` in the returned namespace would + be just ``['args3', 'args4']``. Positional argument with ``nargs='**'``, if + preset, must be the last positional argument. + + .. versionadded:: 3.10 + If the ``nargs`` keyword argument is not provided, the number of arguments consumed is determined by the action_. Generally this means a single command-line argument will be consumed and a single item (not a list) will be produced. diff --git a/Lib/argparse.py b/Lib/argparse.py index 13e641146b4121..67d030fc490e05 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -82,6 +82,7 @@ 'REMAINDER', 'SUPPRESS', 'ZERO_OR_MORE', + 'AS_MANY_AS_POSSIBLE' ] @@ -95,6 +96,7 @@ OPTIONAL = '?' ZERO_OR_MORE = '*' +AS_MANY_AS_POSSIBLE = '**' ONE_OR_MORE = '+' PARSER = 'A...' REMAINDER = '...' @@ -590,7 +592,8 @@ def _format_args(self, action, default_metavar): result = '%s' % get_metavar(1) elif action.nargs == OPTIONAL: result = '[%s]' % get_metavar(1) - elif action.nargs == ZERO_OR_MORE: + elif (action.nargs == ZERO_OR_MORE + or action.nargs == AS_MANY_AS_POSSIBLE): metavar = get_metavar(1) if len(metavar) == 2: result = '[%s [%s ...]]' % metavar @@ -692,7 +695,7 @@ def _get_help_string(self, action): help = action.help if '%(default)' not in action.help: if action.default is not SUPPRESS: - defaulting_nargs = [OPTIONAL, ZERO_OR_MORE] + defaulting_nargs = [OPTIONAL, ZERO_OR_MORE, AS_MANY_AS_POSSIBLE] if action.option_strings or action.nargs in defaulting_nargs: help += ' (default: %(default)s)' return help @@ -781,6 +784,7 @@ class Action(_AttributeHolder): - N (an integer) consumes N arguments (and produces a list) - '?' consumes zero or one arguments - '*' consumes zero or more arguments (and produces a list) + - '**' consumes all remaining positional arguments - '+' consumes one or more arguments (and produces a list) Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with @@ -1515,7 +1519,8 @@ def _get_positional_kwargs(self, dest, **kwargs): # mark positional arguments as required if at least one is # always required - if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]: + if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE, + AS_MANY_AS_POSSIBLE]: kwargs['required'] = True if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs: kwargs['required'] = True @@ -1541,6 +1546,11 @@ def _get_optional_kwargs(self, *args, **kwargs): if len(option_string) > 1 and option_string[1] in self.prefix_chars: long_option_strings.append(option_string) + # nargs='**' is invalid for optionals + if kwargs.get('nargs') == AS_MANY_AS_POSSIBLE: + msg = _("'nargs=\"**\"' is invalid for optionals") + raise TypeError(msg) + # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x' dest = kwargs.pop('dest', None) if dest is None: @@ -1696,8 +1706,7 @@ def __init__(self, conflict_handler='error', add_help=True, allow_abbrev=True, - exit_on_error=True, - greedy=False): + exit_on_error=True): superinit = super(ArgumentParser, self).__init__ superinit(description=description, @@ -1717,7 +1726,6 @@ def __init__(self, self.add_help = add_help self.allow_abbrev = allow_abbrev self.exit_on_error = exit_on_error - self.greedy = greedy add_group = self.add_argument_group self._positionals = add_group(_('positional arguments')) @@ -2021,9 +2029,9 @@ def consume_positionals(start_index): args = arg_strings[start_index: start_index + arg_count] start_index += arg_count take_action(action, args) - # if greedy is on and positional action nargs is '*', + # if positional action nargs is '**', # never remove it from actions list - if not self.greedy or action.nargs != ZERO_OR_MORE: + if action.nargs != AS_MANY_AS_POSSIBLE: action_index += 1 # slice off the Positionals that we just parsed and return the @@ -2298,7 +2306,7 @@ def _get_nargs_pattern(self, action): nargs_pattern = '(-*A?-*)' # allow zero or more arguments - elif nargs == ZERO_OR_MORE: + elif nargs == ZERO_OR_MORE or nargs == AS_MANY_AS_POSSIBLE: nargs_pattern = '(-*[A-]*)' # allow one or more arguments diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 8621d8999a8cc7..37263f342456a6 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5022,9 +5022,9 @@ def test_nongreedy(self): self.assertEqual(NS(first=['arg1', 'arg2'], second='arg3'), args) def test_greedy(self): - parser = argparse.ArgumentParser(greedy=True) + parser = argparse.ArgumentParser() parser.add_argument('--foo', action='store') - parser.add_argument('first', nargs='*', action='extend') + parser.add_argument('first', nargs='**', action='extend') argv = ['arg1', 'arg2', '--foo', 'bar', 'arg3', 'arg4'] args = parser.parse_args(argv) diff --git a/Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst b/Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst deleted file mode 100644 index fad719823850c8..00000000000000 --- a/Misc/NEWS.d/next/Library/2021-01-25-20-17-18.bpo-42973._HL64W.rst +++ /dev/null @@ -1 +0,0 @@ -Added new parameter ``greedy`` to :class:`ArgumentParser` constructor which allows positional arguments with ``nargs='*'`` to match positional arguments interspersed with optional arguments. \ No newline at end of file From 760134f8e07cd02392f8177fa8269e3aec23fdc3 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:16:31 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2021-01-27-11-16-30.bpo-42973.sHk-kI.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-01-27-11-16-30.bpo-42973.sHk-kI.rst diff --git a/Misc/NEWS.d/next/Library/2021-01-27-11-16-30.bpo-42973.sHk-kI.rst b/Misc/NEWS.d/next/Library/2021-01-27-11-16-30.bpo-42973.sHk-kI.rst new file mode 100644 index 00000000000000..b27fdb98bf5084 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-01-27-11-16-30.bpo-42973.sHk-kI.rst @@ -0,0 +1 @@ +New possible value ``'**'`` for ``nargs`` parameter of :func:`ArgumentParser.add_argument` in :mod:`argparse`. \ No newline at end of file From 809589cf76bc8077921dda912644d34b68be28d4 Mon Sep 17 00:00:00 2001 From: Tadek Kijkowski Date: Wed, 27 Jan 2021 14:26:43 +0100 Subject: [PATCH 7/7] bpo-42973: argparse: mixing optional and positional Restored original ArgumentParser signature in argparse.rst --- Doc/library/argparse.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index c25ca5912d0e8e..f969f2f32dc3f7 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -142,8 +142,7 @@ ArgumentParser objects formatter_class=argparse.HelpFormatter, \ prefix_chars='-', fromfile_prefix_chars=None, \ argument_default=None, conflict_handler='error', \ - add_help=True, allow_abbrev=True, exit_on_error=True, \ - greedy=False) + add_help=True, allow_abbrev=True, exit_on_error=True) Create a new :class:`ArgumentParser` object. All parameters should be passed as keyword arguments. Each parameter has its own more detailed description