classification
Title: use proper gettext plurals forms in argparse and optparse
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: LambertDW, aronacher, bethard, dwayne, eric.araujo, georg.brandl, gward, python-dev
Priority: normal Keywords: easy, needs review, patch

Created on 2008-11-22 21:44 by dwayne, last changed 2011-03-20 19:06 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
optparse_proper_gettext_plurals.diff dwayne, 2008-11-22 21:44 Patch to use ngettext for plural entries
optparse_proper_gettext_plurals.diff dwayne, 2008-11-22 22:10 Patch to use ngettext for plural entries
fix-argparse-ngettext.diff eric.araujo, 2010-12-04 17:22
fix-optparse-ngettext.diff eric.araujo, 2010-12-25 18:47 review
Messages (15)
msg76260 - (view) Author: Dwayne Bailey (dwayne) Date: 2008-11-22 21:44
The following code in optparse:

            if len(rargs) < nargs:
                if nargs == 1:
                    self.error(_("%s option requires an argument") % opt)
                else:
                    self.error(_("%s option requires %d arguments")
                               % (opt, nargs))

works for languages with plurals of n!=1 but will not work for many
others that have more sophisticated plurals.

I've created a patch that handles missing gettext and implements it
correctly if it is available. Be aware that I have not been able to test
the patch.
msg76261 - (view) Author: David W. Lambert (LambertDW) Date: 2008-11-22 21:54
And while at it, replace "usage" with "Use".
"Usage" isn't a word.
msg76262 - (view) Author: Dwayne Bailey (dwayne) Date: 2008-11-22 22:10
Mmm some problems with my head late at night.  This patch sorts things
out and makes sure strings can be extracted by xgettext
msg107561 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-11 17:02
Thanks for your patch. I have some remarks:
1) please produce a patch from the top level of a Python checkout (cf. http://www.python.org/dev/patches/);
2) wrap lines under 80 characters;
3) bug with %-formatting: the singular message takes one arg, the plural two (optparse bug, not your patch’s bug, but the patch should fix it too);
4) “usage” has been used for decades in command line parsing, it’s fine.

I’m adding Armin to the nosy list since he’s listed in py3k/Misc/maintainers.rst
msg120530 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-05 20:28
Now that argparse has been included in the standard library to supersede optparse, I’m not sure there is still value in fixing this bug.
msg121539 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-19 15:36
optparse is widely used, so the answer to my question is: yes, it is worth fixing.  Checking argparse for the same errors is also a good idea.

Dwayne: can you update your patch to address my remarks?  If not, someone else or I may do it.  Adding the “easy” keyword for potential bug-day contributors.
msg123286 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-03 19:47
I just checked argparse and there are similar non-optimal calls.  Not all languages can use “string(s)” to express with 0, 1 or more, that’s why we have ngettext.

Georg: This is a string change similar to #10528.  Does it need a patch and review before the beta1 too?
msg123373 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-04 17:22
Attached patch fixes the two misuses I found in argparse.

I tried importing ngettext as _ngettext to comply with arpgarse’s crazy^Wpersonal <wink> import style (enforced in TestImportStar), but then I could not force xgettext to find all the strings.  Rather than struggle longer with the program, I chose to add an exception for ngettext in the test.  “from argparse import *” does not import ngettext, thanks to __all__, so I think my choice is simple and sensible.
msg123375 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-04 17:26
Georg approved my patch for the beta1.  Steven, since you approved my other gettext-related changes, we thing it’s okay if I don’t wait for your +1.

For optparse, I will review the changes later.
msg123377 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-04 17:32
Revision 87056
msg123418 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2010-12-05 10:25
The workaround in TestImportStar is fine. The test is really just meant to make sure that __all__ contains all the current API methods, and the "_" checks were the easiest way at the time to check that.
msg124576 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-23 23:29
Updated patch for optparse.  Georg: Is this okay for 3.2?

Based on Steven’s decision for another patch that changed strings, these fixes won’t be backported.
msg124644 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-25 18:47
Previous version was incomplete.
msg127755 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-02-02 19:56
Looks like this will have to wait for 3.3, unfortunately.
msg131526 - (view) Author: Roundup Robot (python-dev) Date: 2011-03-20 19:06
New changeset 4a5782a2b074 by Éric Araujo in branch 'default':
Use proper gettext plural forms in optparse (closes #4391).
http://hg.python.org/cpython/rev/4a5782a2b074
History
Date User Action Args
2011-03-20 19:06:48python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg131526

resolution: fixed
stage: patch review -> resolved
2011-02-02 19:56:34eric.araujosetversions: + Python 3.3, - Python 3.2
nosy: gward, georg.brandl, bethard, LambertDW, aronacher, eric.araujo, dwayne
messages: + msg127755

keywords: + needs review
stage: patch review
2010-12-25 18:47:38eric.araujosetfiles: + fix-optparse-ngettext.diff
nosy: + gward
messages: + msg124644

2010-12-25 18:44:54eric.araujosetfiles: - fix-optparse-ngettext.diff
nosy: georg.brandl, bethard, LambertDW, aronacher, eric.araujo, dwayne
2010-12-23 23:59:22eric.araujolinkissue10766 dependencies
2010-12-23 23:29:47eric.araujosetfiles: + fix-optparse-ngettext.diff

versions: - Python 3.1, Python 2.7
messages: + msg124576
nosy: georg.brandl, bethard, LambertDW, aronacher, eric.araujo, dwayne
2010-12-12 17:05:15r.david.murraysetpriority: normal
2010-12-05 10:25:45bethardsetmessages: + msg123418
2010-12-04 17:32:56eric.araujosetmessages: + msg123377
2010-12-04 17:26:15eric.araujosetassignee: eric.araujo
messages: + msg123375
2010-12-04 17:22:16eric.araujosetfiles: + fix-argparse-ngettext.diff

messages: + msg123373
title: optparse: use proper gettext plurals forms -> use proper gettext plurals forms in argparse and optparse
2010-12-03 19:47:26eric.araujosetpriority: low -> (no value)
nosy: + georg.brandl, bethard
messages: + msg123286

2010-11-19 15:36:22eric.araujosetkeywords: + easy

messages: + msg121539
2010-11-05 20:28:39eric.araujosetmessages: + msg120530
2010-08-04 23:52:35terry.reedysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.5
2010-06-11 17:02:21eric.araujosetnosy: + aronacher, eric.araujo
messages: + msg107561
2008-11-23 20:21:07rhettingersetpriority: low
2008-11-22 22:10:25dwaynesetfiles: + optparse_proper_gettext_plurals.diff
messages: + msg76262
2008-11-22 21:54:19LambertDWsetnosy: + LambertDW
messages: + msg76261
2008-11-22 21:44:27dwaynecreate