summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-09-24 07:55:33 (GMT)
committerGitHub <noreply@github.com>2024-09-24 07:55:33 (GMT)
commit3c83f9958c14cd62ad8951c53536f7788745b0ba (patch)
tree3e02b7979efb16a34fdf9d7296da4aa9c0d9e08b /Lib/argparse.py
parentc578271366176a1d1b0941897efefb6e4d6508b4 (diff)
downloadcpython-3c83f9958c14cd62ad8951c53536f7788745b0ba.zip
cpython-3c83f9958c14cd62ad8951c53536f7788745b0ba.tar.gz
cpython-3c83f9958c14cd62ad8951c53536f7788745b0ba.tar.bz2
gh-72795: Make positional arguments with nargs='*' or REMAINDER non-required (GH-124306)
This allows to use positional argument with nargs='*' and without default in mutually exclusive group and improves error message about required arguments.
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 89496cb..3974ebe 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1532,9 +1532,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