FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] GH-61082: Clarify nargs='*' positional default behavior (GH-150989) by miss-islington · Pull Request #151168 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions Doc/library/argparse.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ is used when no command-line argument was present::
>>> parser.parse_args([])
Namespace(foo=42)

Because ``nargs='*'`` gathers any supplied values into a list, an absent
positional argument yields an empty list (``[]``). Only a non-``None``
*default* overrides this (so ``default=None`` still gives ``[]``).

For required_ arguments, the ``default`` value is ignored. For example, this
applies to positional arguments with nargs_ values other than ``?`` or ``*``,
or optional arguments marked as ``required=True``.
Expand Down
Loading

Back | FazBrowse Home | New Git URL