summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Bond <federicobond@gmail.com>2019-11-20 10:29:29 -0300
committerTal Einat <taleinat+github@gmail.com>2019-11-20 15:29:29 +0200
commitbe5c79e0338005d675a64ba6e5b137e850d556d1 (patch)
treec8418cd2f3afb3d67fbfde4c125edda37433e9a8
parent4dedd0f0ddc5a983a57bf0105eb34f948a91d2c4 (diff)
downloadcpython-git-be5c79e0338005d675a64ba6e5b137e850d556d1.tar.gz
bpo-38821: Fix crash in argparse when using gettext (GH-17192)
-rw-r--r--Lib/argparse.py5
-rw-r--r--Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst1
2 files changed, 4 insertions, 2 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 94e1b8ad0e..5a8eff2f4c 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -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
diff --git a/Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst b/Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst
new file mode 100644
index 0000000000..2e7a22f661
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst
@@ -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.