Message239275
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) |
|
Date |
User |
Action |
Args |
2015-03-25 16:53:44 | paul.j3 | set | recipients:
+ paul.j3, docs@python, berker.peksag, derks, spaceone |
2015-03-25 16:53:44 | paul.j3 | set | messageid: <1427302424.38.0.707435715743.issue23487@psf.upfronthosting.co.za> |
2015-03-25 16:53:44 | paul.j3 | link | issue23487 messages |
2015-03-25 16:53:44 | paul.j3 | create | |
|