bpo-38821: Fix crash in argparse when using gettext (GH-17192)

This commit is contained in:
Federico Bond 2019-11-20 10:29:29 -03:00 committed by Tal Einat
parent 4dedd0f0dd
commit be5c79e033
2 changed files with 4 additions and 2 deletions

View File

@ -2148,10 +2148,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
OPTIONAL: _('expected at most one argument'),
ONE_OR_MORE: _('expected at least one argument'),
}
default = ngettext('expected %s argument',
msg = nargs_errors.get(action.nargs)
if msg is None:
msg = ngettext('expected %s argument',
'expected %s arguments',
action.nargs) % action.nargs
msg = nargs_errors.get(action.nargs, default)
raise ArgumentError(action, msg)
# return the number of arguments matched

View File

@ -0,0 +1 @@
Fix unhandled exceptions in :mod:`argparse` when internationalizing error messages for arguments with ``nargs`` set to special (non-integer) values. Patch by Federico Bond.