Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use proper gettext plurals forms in argparse and optparse #48641

Closed
dwayne mannequin opened this issue Nov 22, 2008 · 15 comments
Closed

use proper gettext plurals forms in argparse and optparse #48641

dwayne mannequin opened this issue Nov 22, 2008 · 15 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dwayne
Copy link
Mannequin

dwayne mannequin commented Nov 22, 2008

BPO 4391
Nosy @birkenfeld, @mitsuhiko, @merwok
Files
  • optparse_proper_gettext_plurals.diff: Patch to use ngettext for plural entries
  • optparse_proper_gettext_plurals.diff: Patch to use ngettext for plural entries
  • fix-argparse-ngettext.diff
  • fix-optparse-ngettext.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/merwok'
    closed_at = <Date 2011-03-20.19:06:48.525>
    created_at = <Date 2008-11-22.21:44:27.655>
    labels = ['easy', 'type-bug', 'library']
    title = 'use proper gettext plurals forms in argparse and optparse'
    updated_at = <Date 2011-03-20.19:06:48.524>
    user = 'https://bugs.python.org/dwayne'

    bugs.python.org fields:

    activity = <Date 2011-03-20.19:06:48.524>
    actor = 'python-dev'
    assignee = 'eric.araujo'
    closed = True
    closed_date = <Date 2011-03-20.19:06:48.525>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2008-11-22.21:44:27.655>
    creator = 'dwayne'
    dependencies = []
    files = ['12107', '12108', '19941', '20164']
    hgrepos = []
    issue_num = 4391
    keywords = ['patch', 'easy', 'needs review']
    message_count = 15.0
    messages = ['76260', '76261', '76262', '107561', '120530', '121539', '123286', '123373', '123375', '123377', '123418', '124576', '124644', '127755', '131526']
    nosy_count = 8.0
    nosy_names = ['gward', 'georg.brandl', 'bethard', 'LambertDW', 'aronacher', 'eric.araujo', 'dwayne', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4391'
    versions = ['Python 3.3']

    @dwayne
    Copy link
    Mannequin Author

    dwayne mannequin commented Nov 22, 2008

    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.

    @dwayne dwayne mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 22, 2008
    @lambertdw
    Copy link
    Mannequin

    lambertdw mannequin commented Nov 22, 2008

    And while at it, replace "usage" with "Use".
    "Usage" isn't a word.

    @dwayne
    Copy link
    Mannequin Author

    dwayne mannequin commented Nov 22, 2008

    Mmm some problems with my head late at night. This patch sorts things
    out and makes sure strings can be extracted by xgettext

    @merwok
    Copy link
    Member

    merwok commented Jun 11, 2010

    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

    @merwok
    Copy link
    Member

    merwok commented Nov 5, 2010

    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.

    @merwok
    Copy link
    Member

    merwok commented Nov 19, 2010

    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.

    @merwok merwok added the easy label Nov 19, 2010
    @merwok
    Copy link
    Member

    merwok commented Dec 3, 2010

    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 bpo-10528. Does it need a patch and review before the beta1 too?

    @merwok
    Copy link
    Member

    merwok commented Dec 4, 2010

    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.

    @merwok merwok changed the title optparse: use proper gettext plurals forms use proper gettext plurals forms in argparse and optparse Dec 4, 2010
    @merwok
    Copy link
    Member

    merwok commented Dec 4, 2010

    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.

    @merwok merwok self-assigned this Dec 4, 2010
    @merwok
    Copy link
    Member

    merwok commented Dec 4, 2010

    Revision 87056

    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Dec 5, 2010

    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.

    @merwok
    Copy link
    Member

    merwok commented Dec 23, 2010

    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.

    @merwok
    Copy link
    Member

    merwok commented Dec 25, 2010

    Previous version was incomplete.

    @merwok
    Copy link
    Member

    merwok commented Feb 2, 2011

    Looks like this will have to wait for 3.3, unfortunately.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 20, 2011

    New changeset 4a5782a2b074 by Éric Araujo in branch 'default':
    Use proper gettext plural forms in optparse (closes bpo-4391).
    http://hg.python.org/cpython/rev/4a5782a2b074

    @python-dev python-dev mannequin closed this as completed Mar 20, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant