| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Documentation build overview17 files changed · ± 17 modified ± Modified |
Sorry, something went wrong.
| 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 ``[]``). | ||
|
|
There was a problem hiding this comment.
I tested the nargs="*" cases in the REPL to make sure I followed it: with default=None it returns an empty list and a non-None default overrides it. The note reads clearly to me.
>>> import argparse
>>> p = argparse.ArgumentParser()
>>> p.add_argument("foo", nargs="*", default=None)
_StoreAction(option_strings=[], dest='foo', nargs='*', const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)
>>> p.parse_args([])
Namespace(foo=[])
>>> p2 = argparse.ArgumentParser()
>>> p2.add_argument("foo", nargs="*", default=[1, 2, 3])
_StoreAction(option_strings=[], dest='foo', nargs='*', const=None, default=[1, 2, 3], type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)
>>> p2.parse_args([])
Namespace(foo=[1, 2, 3])
Sorry, something went wrong.
|
Thanks @savannahostrowski for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
Sorry, something went wrong.
|
GH-151168 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
|
GH-151169 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-151170 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.