bpo-38821: Fix crash in argparse when using gettext (GH-17192)
(cherry picked from commit be5c79e0338005d675a64ba6e5b137e850d556d1)
Co-authored-by: Federico Bond <federicobond@gmail.com>
diff --git a/Lib/argparse.py b/Lib/argparse.py
index e590225..fd61bc7 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -2093,10 +2093,11 @@
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