You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you please elaborate the expected behavior here ?
I believe the expected behaviour for passing an empty list with nargs="*" should be the same behaviour as passing an empty list with nargs="?" since * is 0 or more arguments whereas ? is 0 or 1 arguments.
>>> from argparse import ArgumentParser
>>> p = ArgumentParser()
>>> p.add_argument('dessert', nargs="?", choices=('cake', 'pie'))
>>> p.parse_args([])
Namespace(dessert=None)
This only happens for a positional. nargs='*' (and '?') gets some special handling in get_values, when an emply list satisfies its nargs. The default is assigned in place of the empty list.
This is part of the logic that allows us to use these positionals in a mutually_exclusive_group.
In the code below, it is valid to supply no arguments.
However, the following error is generated:
What is happening is that the empty list is being treated a value rather than a collection of values.
The text was updated successfully, but these errors were encountered: