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 paul.j3
Recipients DasIch, G2P, Julian, bethard, bewest, bkabrda, chris.jerdonek, csernazs, dsully, elsdoerfer, eric.araujo, labrat, nvie, paul.j3, r.david.murray, seblu, zzzeek
Date 2013-04-09.07:08:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I think this problem arises from a change made in

Changeset to default (i.e. development) is

Near the end of _parse_known_args it removes a:

    if positionals:
       self.error(_('too few arguments'))

with a scan for required options that have not been seen. 

Ordinary positionals are required.  But a SubParsersAction is not required.  So we no longer get a warning. changed this block of code as well.  Notice the 2.7 and 3.2 branches have this 'too few arguments' error, but the default does not.

The default value for Action.required is False.  In _get_positional_kwargs(), a positional's required is set based on nargs (e.g. '+' is required, '*' not).  But add_subparsers() does not use this, so its 'required' ends up False.

This fudge seems to do the trick:

   parser = ArgumentParser(prog='test')
   subparsers = parser.add_subparsers()
   subparsers.required = True
   subparsers.dest = 'command'
   subparser = subparsers.add_parser("foo", help="run foo")

producing an error message:

   usage: test [-h] {foo} ...
   test: error: the following arguments are required: command

subparsers.dest is set so the error message can give this positional a name.

I'll try to write a patch to do something similar in argparse itself.
Date User Action Args
2013-04-09 07:08:43paul.j3setrecipients: + paul.j3, csernazs, bethard, eric.araujo, r.david.murray, zzzeek, labrat, chris.jerdonek, nvie, DasIch, elsdoerfer, G2P, Julian, dsully, seblu, bewest, bkabrda
2013-04-09 07:08:43paul.j3setmessageid: <>
2013-04-09 07:08:43paul.j3linkissue9253 messages
2013-04-09 07:08:42paul.j3create