I want to display default values, argument type, and big spacing for --help.
But if I do
import argparse
class F(argparse.MetavarTypeHelpFormatter, argparse.ArgumentDefaultsHelpFormatter, lambda prog: argparse.HelpFormatter(prog, max_help_position = 52)): pass
parser = argparse.ArgumentParser(
prog = 'junk',
formatter_class = F)
It gives the following error
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Does anyone know how to combine these three formatters correctly?
Separating the lambda part works
The lambda expression isn't used to make a new subclass, but to modify how the class is called.
On the argparse bug/issues board it has been suggested that you can subclass the helpformatter by inheriting from several of the provided subclasses. But no one has tested all combinations. The provided subclasses just modify one or more of the formatter methods to produce the desired change. You could make those changes directly in your class. Read the argparse.py code to see how
On using the
lambdaformatter:Explain lambda argparse.HelpFormatter(prog, width)
I show how you can do by subclassing, but the
lambdaexpression is simpler.Also
where is the documentation for the python argparse helpformatter class?