Message187226
The 'subparsers' object has a _parser_class attribute that is normally set to the class of the parent parser. In the attached file I create a
class CustomParser(argparse.ArgumentParser)
that makes a parser instance which copies all of the attributes of prototype parser.
proto1 = argparse.ArgumentParser(prog='SUBPROG1')
proto1.add_argument('--foo')
subparsers._parser_class = CustomParser
sub1 = subparsers.add_parser('cmd1', proto=proto1, help='parser based on proto1')
'sub1' is a functional copy of 'proto1'. I think this does what you want without changing the argparse code. There probably is a way of defining CustomParser (maybe its '__new__' method) so 'sub1' is actually 'proto1'. But the copy approach appears to work just fine. |
|
Date |
User |
Action |
Args |
2013-04-18 07:06:53 | paul.j3 | set | recipients:
+ paul.j3, bethard, chris.jerdonek |
2013-04-18 07:06:53 | paul.j3 | set | messageid: <1366268813.63.0.876913201999.issue17204@psf.upfronthosting.co.za> |
2013-04-18 07:06:53 | paul.j3 | link | issue17204 messages |
2013-04-18 07:06:53 | paul.j3 | create | |
|