From 72eac266e7b738df90637873c29d043164222a16 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Sat, 16 Nov 2019 14:46:37 -0300 Subject: [PATCH 1/4] bpo-38821: Fix crash in argparse when using gettext gettext deprecated non-integer arguments for ngettext in bpo-28692 --- Lib/argparse.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 94e1b8ad0ed18e..5a8eff2f4cc893 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2148,10 +2148,11 @@ def _match_argument(self, action, arg_strings_pattern): 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 From 7c58f52b8a7aac2139cc253c0a1d25af9c5f3e03 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2019 23:26:25 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst 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 00000000000000..cf926042ec81e7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst @@ -0,0 +1 @@ +Fix crash in argparse when using gettext. \ No newline at end of file From 0a848c632bd09be5d1579ad5075ba576e6c39bcd Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Tue, 19 Nov 2019 13:55:21 -0300 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst Co-Authored-By: Brandt Bucher --- .../next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index cf926042ec81e7..03db7cae34c014 100644 --- 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 @@ -1 +1 @@ -Fix crash in argparse when using gettext. \ No newline at end of file +Fix unhandled exceptions in :mod:`argparse` when internationalizing some error messages. From 877600b03d81b9dcdc3e63b35778622d35d27751 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Wed, 20 Nov 2019 09:38:53 -0300 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst Co-Authored-By: Tal Einat --- .../next/Library/2019-11-16-23-26-25.bpo-38821.-albNN.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 03db7cae34c014..2e7a22f661ac69 100644 --- 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 @@ -1 +1 @@ -Fix unhandled exceptions in :mod:`argparse` when internationalizing some error messages. +Fix unhandled exceptions in :mod:`argparse` when internationalizing error messages for arguments with ``nargs`` set to special (non-integer) values. Patch by Federico Bond.