paul j3 added the comment:

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.

----------
nosy: +paul.j3
Added file: http://bugs.python.org/file29916/issue17204.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17204>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to