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
This commit is contained in:
tmblweed 2019-08-01 21:57:13 -07:00 • committed by Miss Islington (bot)
parent 2491134029
commit 4b3e975923
4 changed files with 38 additions and 4 deletions

View file

@ -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: