[issue20430] Make argparse.SUPPRESS work as an argument "dest"

paul j3 report at bugs.python.org
Mon Apr 25 01:24:44 EDT 2016


paul j3 added the comment:

I just found a case where `dest` is `SUPPRESS` - the default subparsers setup.

      _SubParsersAction(option_strings=[], dest='==SUPPRESS==', nargs='A...', ...

If I make this Action 'required' (in the current distribution 'subparsers' are not required - there's a bug/issue for that)

     parser._actions[1].required=True

and call the parser without the required subparser argument I should get an error message.  In earlier versions this would have been a non specific,  `error: too few arguments', but the new one tries to name the missing argument, e.g.

    program: error: the following arguments are required: choice

But with SUPPRESS I get a further error as _parse_known_args tries to format this error message:

C:\Users\paul\Miniconda3\lib\argparse.py in _parse_known_args(self, arg_strings, namespace)
   1991         if required_actions:
   1992             self.error(_('the following arguments are required: %s') %
-> 1993                        ', '.join(required_actions))

TypeError: sequence item 0: expected str instance, NoneType found

(This error may have been reported elsewhere.  This issue is the first one I found that deals with `dest=argparse.SUPPRESS`.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20430>
_______________________________________


More information about the Python-bugs-list mailing list