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.

classification
Title: argparse: default propagation of formatter_class from ArgumentParser() to SubParsers
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Gieskanne, paul.j3
Priority: normal Keywords:

Created on 2016-09-01 10:06 by Gieskanne, last changed 2022-04-11 14:58 by admin.

Messages (2)
msg274114 - (view) Author: Gieskanne (Gieskanne) Date: 2016-09-01 10:06
It would be nice to propagate the formatter_class defined in argparse.ArgumentParser() to added SubParsers by default. Currently one has to define the formatter_class for each subparser again and again.

Example:
    parser = argparse.ArgumentParser(description='property', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    subparsers = parser.add_subparsers(help='sub-command help')
    pcar = subparsers.add_parser('car', help='add car', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    pcar.add_argument('--color', help='color of car', default='red')
    pyacht = subparsers.add_parser('yacht', help='add yacht', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    pyacht.add_argument('--length', help='length of yacht [m]', default=12.5)
msg274334 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2016-09-04 04:00
http://bugs.python.org/issue21633

also deals with the formatter of subparsers.  I note there that few of parameters of the main parser propagate to the subparsers.  

The current design gives the programmer maximum control, at the expense of a bit of typing.  If I had to create a large number of subparsers, I might write a utility function to take care of the repetitious tasks.
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72114
2016-09-04 04:00:54paul.j3setnosy: + paul.j3
messages: + msg274334
2016-09-01 10:06:59Gieskannecreate