mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
[3.13] gh-72795: Make positional arguments with nargs='*' or REMAINDER non-required (GH-124306) (#124421)
This allows to use positional argument with nargs='*' and without default
in mutually exclusive group and improves error message about required
arguments.
(cherry picked from commit 3c83f9958c)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
db3ccd8b62
commit
0a046771c0
3 changed files with 32 additions and 8 deletions
|
|
@ -1561,9 +1561,8 @@ class _ActionsContainer(object):
|
|||
|
||||
# mark positional arguments as required if at least one is
|
||||
# always required
|
||||
if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
|
||||
kwargs['required'] = True
|
||||
if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
|
||||
nargs = kwargs.get('nargs')
|
||||
if nargs not in [OPTIONAL, ZERO_OR_MORE, REMAINDER, SUPPRESS, 0]:
|
||||
kwargs['required'] = True
|
||||
|
||||
# return the keyword arguments with no option strings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue