Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1215915

Browse files
committed
Use proper plural forms in argparse (#4391)
1 parent 13d49ee commit 1215915

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/argparse.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import sys as _sys
8989
import textwrap as _textwrap
9090

91-
from gettext import gettext as _
91+
from gettext import gettext as _, ngettext
9292

9393

9494
def _callable(obj):
@@ -1438,7 +1438,9 @@ def _check_conflict(self, action):
14381438
conflict_handler(action, confl_optionals)
14391439

14401440
def _handle_conflict_error(self, action, conflicting_actions):
1441-
message = _('conflicting option string(s): %s')
1441+
message = ngettext('conflicting option string: %s',
1442+
'conflicting option strings: %s',
1443+
len(conflicting_actions))
14421444
conflict_string = ', '.join([option_string
14431445
for option_string, action
14441446
in conflicting_actions])
@@ -1995,7 +1997,9 @@ def _match_argument(self, action, arg_strings_pattern):
19951997
OPTIONAL: _('expected at most one argument'),
19961998
ONE_OR_MORE: _('expected at least one argument'),
19971999
}
1998-
default = _('expected %s argument(s)') % action.nargs
2000+
default = ngettext('expected %s argument',
2001+
'expected %s arguments',
2002+
action.nargs) % action.nargs
19992003
msg = nargs_errors.get(action.nargs, default)
20002004
raise ArgumentError(action, msg)
20012005

Lib/test/test_argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4315,7 +4315,7 @@ def test_all_exports_everything_but_modules(self):
43154315
items = [
43164316
name
43174317
for name, value in vars(argparse).items()
4318-
if not name.startswith("_")
4318+
if not (name.startswith("_") or name == 'ngettext')
43194319
if not inspect.ismodule(value)
43204320
]
43214321
self.assertEqual(sorted(items), sorted(argparse.__all__))

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Core and Builtins
4949
Library
5050
-------
5151

52+
- Issue #4391: Use proper plural forms in argparse.
53+
5254
- Issue #10601: sys.displayhook uses 'backslashreplace' error handler on
5355
UnicodeEncodeError.
5456

0 commit comments

Comments
 (0)