Skip to content

Commit be5c79e

Browse files
federicobondtaleinat
authored andcommitted
bpo-38821: Fix crash in argparse when using gettext (GH-17192)
1 parent 4dedd0f commit be5c79e

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
@@ -2148,10 +2148,11 @@ def _match_argument(self, action, arg_strings_pattern):
21482148
OPTIONAL: _('expected at most one argument'),
21492149
ONE_OR_MORE: _('expected at least one argument'),
21502150
}
2151-
default = ngettext('expected %s argument',
2151+
msg = nargs_errors.get(action.nargs)
2152+
if msg is None:
2153+
msg = ngettext('expected %s argument',
21522154
'expected %s arguments',
21532155
action.nargs) % action.nargs
2154-
msg = nargs_errors.get(action.nargs, default)
21552156
raise ArgumentError(action, msg)
21562157

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