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 bethard, chris.jerdonek, paul.j3
Date 2013-04-18.07:06:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366268813.63.0.876913201999.issue17204@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-04-18 07:06:53paul.j3setrecipients: + paul.j3, bethard, chris.jerdonek
2013-04-18 07:06:53paul.j3setmessageid: <1366268813.63.0.876913201999.issue17204@psf.upfronthosting.co.za>
2013-04-18 07:06:53paul.j3linkissue17204 messages
2013-04-18 07:06:53paul.j3create