Skip to content

Commit ecb2afc

Browse files
bpo-38821: Fix crash in argparse when using gettext (GH-17192)
(cherry picked from commit be5c79e) Co-authored-by: Federico Bond <[email protected]>
1 parent 1d7245c commit ecb2afc

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/argparse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,10 +2080,11 @@ def _match_argument(self, action, arg_strings_pattern):
20802080
OPTIONAL: _('expected at most one argument'),
20812081
ONE_OR_MORE: _('expected at least one argument'),
20822082
}
2083-
default = ngettext('expected %s argument',
2083+
msg = nargs_errors.get(action.nargs)
2084+
if msg is None:
2085+
msg = ngettext('expected %s argument',
20842086
'expected %s arguments',
20852087
action.nargs) % action.nargs
2086-
msg = nargs_errors.get(action.nargs, default)
20872088
raise ArgumentError(action, msg)
20882089

20892090
# return the number of arguments matched
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)