This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.fahlgren
Recipients eric.fahlgren
Date 2019-01-19.17:38:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1547919486.3.0.425644467841.issue35785@roundup.psfhosted.org>
In-reply-to
Content
When argparse is configured with an option that takes arguments, then the script is invoked with the switch but no arguments, a nonsensical exception is raised during gettext processing.

In the 3.7.1 source, the error is at line 2077 of argparse.py, where 'action.nargs' is not an integer as expected by 'ngettext', but one of None, '*' or '?':

            default = ngettext('expected %s argument',
                               'expected %s arguments',
                               action.nargs) % action.nargs
            msg = nargs_errors.get(action.nargs, default)

Fix should be pretty trivial, swap the two lines and if 'get' produces None, only then compute the default.

  File "C:\Program Files\Python37\lib\argparse.py", line 1749, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "C:\Program Files\Python37\lib\argparse.py", line 1781, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "C:\Program Files\Python37\lib\argparse.py", line 1987, in _parse_known_args
    start_index = consume_optional(start_index)
  File "C:\Program Files\Python37\lib\argparse.py", line 1917, in consume_optional
    arg_count = match_argument(action, selected_patterns)
  File "C:\Program Files\Python37\lib\argparse.py", line 2079, in _match_argument
    action.nargs) % action.nargs
  File "C:\Program Files\Python37\lib\gettext.py", line 631, in ngettext
    return dngettext(_current_domain, msgid1, msgid2, n)
  File "C:\Program Files\Python37\lib\gettext.py", line 610, in dngettext
    return t.ngettext(msgid1, msgid2, n)
  File "C:\Program Files\Python37\lib\gettext.py", line 462, in ngettext
    tmsg = self._catalog[(msgid1, self.plural(n))]
  File "<string>", line 4, in func
  File "C:\Program Files\Python37\lib\gettext.py", line 168, in _as_int
    (n.__class__.__name__,)) from None
TypeError: Plural value must be an integer, got NoneType
History
Date User Action Args
2019-01-19 17:38:09eric.fahlgrensetrecipients: + eric.fahlgren
2019-01-19 17:38:06eric.fahlgrensetmessageid: <1547919486.3.0.425644467841.issue35785@roundup.psfhosted.org>
2019-01-19 17:38:06eric.fahlgrenlinkissue35785 messages
2019-01-19 17:38:06eric.fahlgrencreate