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 berker.peksag, derks, docs@python, paul.j3, spaceone
Date 2015-03-25.16:53:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1427302424.38.0.707435715743.issue23487@psf.upfronthosting.co.za>
In-reply-to
Content
As to the nature of the error when 'add_subparsers' is given an 'action' parameter:

'add_subparsers' does several things to 'kwargs' before it passes them to the relevant Action class.

     def add_subparsers(self, **kwargs):
        # adds 'parser_class'
        # removes 'title', 'description' (used in an argument group)
        # add 'prog'
        parsers_class = self._pop_action_class(kwargs, 'parsers')
        action = parsers_class(option_strings=[], **kwargs)

What I wrote earlier about using the registry is partly wrong.  The Action class is determined by either the 'action' parameter or the registry entry.

     In [17]: p._pop_action_class({}, 'parsers')
     Out[17]: argparse._SubParsersAction

     In [18]: p._pop_action_class({'action':'test'}, 'parsers')
     Out[18]: 'test'

So the 'action' parameter works - if you specify a compatible Action class.

    sp=p.add_subparsers(dest='cmd',action=argparse._SubParsersAction)

Such a class must have the same __init__ signature, otherwise you'll get errors such the OP's.

It might be worth rewriting the documentation line so this is clearer.  Otherwise I recommend closing this issue.






     action = parsers_class(option_strings=[], **kwargs)
History
Date User Action Args
2015-03-25 16:53:44paul.j3setrecipients: + paul.j3, docs@python, berker.peksag, derks, spaceone
2015-03-25 16:53:44paul.j3setmessageid: <1427302424.38.0.707435715743.issue23487@psf.upfronthosting.co.za>
2015-03-25 16:53:44paul.j3linkissue23487 messages
2015-03-25 16:53:44paul.j3create