aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmblweed <tmblweed@users.noreply.github.com>2019-08-01 21:57:13 -0700
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-08-01 21:57:13 -0700
commit4b3e97592376d5f8a3b75192b399a2da1be642cb (patch)
treeeba27853c200ae6a4196410b5770871222265bac /Lib/argparse.py
parentbpo-37726: Prefer argparse over getopt in stdlib tutorial (#15052) (diff)
downloadcpython-4b3e97592376d5f8a3b75192b399a2da1be642cb.tar.gz
cpython-4b3e97592376d5f8a3b75192b399a2da1be642cb.tar.bz2
cpython-4b3e97592376d5f8a3b75192b399a2da1be642cb.zip
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
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index e45b67b6770..a300828f9e3 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -593,7 +593,10 @@ class HelpFormatter(object):
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 @@ class _StoreAction(Action):
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 @@ class _AppendAction(Action):
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: