Skip to content

Commit 93406f1

Browse files
committed
gh-110131: Document argparse's extend action with a non-empty default
The 'append' bullet says that a non-empty list default is kept and that command-line values land after it. 'extend' works the same way for an option, but the docs say nothing about it, which is the confusion reported in gh-110131. The sentence is scoped to the option deliberately. For a positional with nargs='*' or '?' and no command-line values, _get_values hands the default back as the parsed value while the same default is already in the namespace, so the action applies it twice and extend(default=['X']) yields ['X', 'X']. The unqualified wording would be wrong there.
1 parent 0546b5f commit 93406f1

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎Doc/library/argparse.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,9 @@ how the command-line arguments should be handled. The supplied actions are:
818818
value ``'+'`` or ``'*'``.
819819
Note that when nargs_ is ``None`` (the default) or ``'?'``, each
820820
character of the argument string will be appended to the list.
821+
If the default value is a non-empty list, the parsed value for the option
822+
will start with the default list's elements and any values from the
823+
command line will be appended after those default values.
821824
Example usage::
822825

823826
>>> parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)