Skip to content

Commit 836f137

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 daf7a08 commit 836f137

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
@@ -2093,10 +2093,11 @@ def _match_argument(self, action, arg_strings_pattern):
20932093
OPTIONAL: _('expected at most one argument'),
20942094
ONE_OR_MORE: _('expected at least one argument'),
20952095
}
2096-
default = ngettext('expected %s argument',
2096+
msg = nargs_errors.get(action.nargs)
2097+
if msg is None:
2098+
msg = ngettext('expected %s argument',
20972099
'expected %s arguments',
20982100
action.nargs) % action.nargs
2099-
msg = nargs_errors.get(action.nargs, default)
21002101
raise ArgumentError(action, msg)
21012102

21022103
# 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)