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

argparse calls ngettext with deprecated non-integer value #83002

Closed
federicobond mannequin opened this issue Nov 16, 2019 · 5 comments
Closed

argparse calls ngettext with deprecated non-integer value #83002

federicobond mannequin opened this issue Nov 16, 2019 · 5 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@federicobond
Copy link
Mannequin

federicobond mannequin commented Nov 16, 2019

BPO 38821
Nosy @taleinat, @miss-islington, @federicobond
PRs
  • bpo-38821: Fix crash in argparse when using gettext #17192
  • [3.7] bpo-38821: Fix crash in argparse when using gettext (GH-17192) #17288
  • [3.8] bpo-38821: Fix crash in argparse when using gettext (GH-17192) #17289
  • 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 = None
    closed_at = <Date 2019-11-20.13:32:39.625>
    created_at = <Date 2019-11-16.17:43:26.771>
    labels = ['3.8', '3.7', 'library', '3.9', 'type-crash']
    title = 'argparse calls ngettext with deprecated non-integer value'
    updated_at = <Date 2019-11-20.13:48:29.253>
    user = 'https://github.com/federicobond'

    bugs.python.org fields:

    activity = <Date 2019-11-20.13:48:29.253>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-11-20.13:32:39.625>
    closer = 'taleinat'
    components = ['Library (Lib)']
    creation = <Date 2019-11-16.17:43:26.771>
    creator = 'federicobond'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38821
    keywords = ['patch']
    message_count = 5.0
    messages = ['356761', '357069', '357070', '357071', '357072']
    nosy_count = 4.0
    nosy_names = ['taleinat', 'paul.j3', 'miss-islington', 'federicobond']
    pr_nums = ['17192', '17288', '17289']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue38821'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @federicobond
    Copy link
    Mannequin Author

    federicobond mannequin commented Nov 16, 2019

    The call to 'ngettext' in 'ArgumentParser._match_argument' (Lib/argparse.py) uses a non-integer value, which causes it to fail with a nonsensical exception. Non-integer values were deprecated in bpo-28692.

    This happens because the 'default' error message is computed unconditionally, even when the value of 'action.nargs' is 'None' and another message will be ultimately selected.

    This issue is similar to bpo-35785 which was not reproduced by other people at the moment and was eventually closed. I could not create a short reproducer but could match several of the points described in that issue. A little debugging turned up that gettext was loading a catalog from the 'natural' PyPI package which uses 'Plural-Forms' too.

    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py", line 1755, in parse_args
    args, argv = self.parse_known_args(args, namespace)
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py", line 1787, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py", line 1993, in _parse_known_args
    start_index = consume_optional(start_index)
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py", line 1923, in consume_optional
    arg_count = match_argument(action, selected_patterns)
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/argparse.py", line 2086, in _match_argument
    action.nargs) % action.nargs
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gettext.py", line 631, in ngettext
    return dngettext(current_domain, msgid1, msgid2, n)
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gettext.py", line 610, in dngettext
    return t.ngettext(msgid1, msgid2, n)
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gettext.py", line 462, in ngettext
    tmsg = self._catalog[(msgid1, self.plural(n))]
    File "<string>", line 4, in func
    File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/gettext.py", line 168, in _as_int
    (n.__class
    _.__name__,)) from None
    TypeError: Plural value must be an integer, got NoneType

    @federicobond federicobond mannequin added 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Nov 16, 2019
    @taleinat
    Copy link
    Contributor

    New changeset be5c79e by Tal Einat (Federico Bond) in branch 'master':
    bpo-38821: Fix crash in argparse when using gettext (GH-17192)
    be5c79e

    @taleinat
    Copy link
    Contributor

    Thanks for the report and the PR with a fix, Federico!

    As discussed on in the PR comments, the PR did not include tests since there are currently no tests for argparse i18n. Please create a new issue for that, referencing this one.

    @taleinat taleinat added the 3.7 (EOL) end of life label Nov 20, 2019
    @miss-islington
    Copy link
    Contributor

    New changeset ecb2afc by Miss Islington (bot) in branch '3.7':
    bpo-38821: Fix crash in argparse when using gettext (GH-17192)
    ecb2afc

    @miss-islington
    Copy link
    Contributor

    New changeset 836f137 by Miss Islington (bot) in branch '3.8':
    bpo-38821: Fix crash in argparse when using gettext (GH-17192)
    836f137

    @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
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants