bpo-16970: Adding error message for invalid args (GH-14844)
BPO -16970: Adding error message for invalid args
Applied the patch argparse-v2 patch issue 16970, ran patch check and the test suite, test_argparse with 0 errors
https://bugs.python.org/issue16970
(cherry picked from commit 4b3e97592376d5f8a3b75192b399a2da1be642cb)
Co-authored-by: tmblweed <tmblweed@users.noreply.github.com>
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 5820d0d..6f0b37c 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -593,7 +593,10 @@
elif action.nargs == SUPPRESS:
result = ''
else:
- formats = ['%s' for _ in range(action.nargs)]
+ try:
+ formats = ['%s' for _ in range(action.nargs)]
+ except TypeError:
+ raise ValueError("invalid nargs value") from None
result = ' '.join(formats) % get_metavar(action.nargs)
return result
@@ -850,7 +853,7 @@
help=None,
metavar=None):
if nargs == 0:
- raise ValueError('nargs for store actions must be > 0; if you '
+ raise ValueError('nargs for store actions must be != 0; if you '
'have nothing to store, actions such as store '
'true or store const may be more appropriate')
if const is not None and nargs != OPTIONAL:
@@ -942,7 +945,7 @@
help=None,
metavar=None):
if nargs == 0:
- raise ValueError('nargs for append actions must be > 0; if arg '
+ raise ValueError('nargs for append actions must be != 0; if arg '
'strings are not supplying the value to append, '
'the append const action may be more appropriate')
if const is not None and nargs != OPTIONAL: