[issue21633] Argparse does not propagate HelpFormatter class to subparsers

2021-05-27 Thread Irit Katriel


Irit Katriel  added the comment:

What Paul explained is also covered in the documentation here: 
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_subparsers

--
nosy: +iritkatriel
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21633] Argparse does not propagate HelpFormatter class to subparsers

2014-06-02 Thread paul j3

paul j3 added the comment:

You can specify the 'formatter_class' when creating each subparser:

sp1=sp.add_parser('cmd1', formatter_class = 
argparse.RawDescriptionHelpFormatter)

The 'add_parser' command is the one that passes a variety of **kwargs to 
'ArgumentParser' (or what ever parser creator is being used for the 
subparsers).  'add_subparsers' is more like a 'add_argument' command, creating 
a '_SubParsersAction' instance.

Few, if any, attributes of the main parser are propagated to the subparsers.  
I'd have to study the code more closely, but I think it's just the parser class 
that is propagated.

--
nosy: +paul.j3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21633
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21633] Argparse does not propagate HelpFormatter class to subparsers

2014-06-01 Thread Michael Cohen

New submission from Michael Cohen:

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.

--
components: Extension Modules
messages: 219534
nosy: Michael.Cohen
priority: normal
severity: normal
status: open
title: Argparse does not propagate HelpFormatter class to subparsers
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21633
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com