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 Michael.Cohen
Recipients Michael.Cohen
Date 2014-06-01.23:32:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1401665556.26.0.881749322578.issue21633@psf.upfronthosting.co.za>
In-reply-to
Content
Argparse has an option to set the custom help formatter class as a kwarg. For example one can define:


class MyHelpFormatter(argparse.RawDescriptionHelpFormatter):
    def add_argument(self, action):
        if action.dest != "SUPPRESS":
            super(RekallHelpFormatter, self).add_argument(action)


parser = ArguementParser(
   formatter_class=MyHelpFormatter)


But when one creates a subparser there is no way to define the formatter class for it - i.e. parser.add_subparsers() does not accept a formatter_class parameter. Instead we see this code:

    def add_subparsers(self, **kwargs):
        ...
        # add the parser class to the arguments if it's not present
        kwargs.setdefault('parser_class', type(self))

The only way to make this work is to extend ArguementParser to force it to use the formatter_class through inheritance:

class MyArgParser(argparse.ArgumentParser):

    def __init__(self, **kwargs):
        kwargs["formatter_class"] = MyHelpFormatter
	super(MyArgParser, self).__init__(**kwargs)

this is counter intuitive since formatter_class can be passed to the constructor but then it is not propagated to subparsers.

IMHO the expect action here is to have the formatter_class automatically propagates to subparsers as well. Short of that we need to be able to specific it in add_subparser() call.
History
Date User Action Args
2014-06-01 23:32:36Michael.Cohensetrecipients: + Michael.Cohen
2014-06-01 23:32:36Michael.Cohensetmessageid: <1401665556.26.0.881749322578.issue21633@psf.upfronthosting.co.za>
2014-06-01 23:32:36Michael.Cohenlinkissue21633 messages
2014-06-01 23:32:35Michael.Cohencreate