[issue22848] Subparser help does not respect SUPPRESS argument

paul j3 report at bugs.python.org
Sun May 6 23:03:40 EDT 2018


paul j3 <ajipanca at gmail.com> added the comment:

I've attached a file that tries out the idea of building a custom `metavar` in the `add_parser` method.

It subclasses argparse._SubParsersAction, and registers it with the parser.  No other modification to production code is required.

Subparsers with a blank `help`, appear in the choices, but not the helps.

Subparsers with a SUPPRESS don't appear in either, but can still appear in error messages

If everything is SUPPRESS, the metavar is '{}'.  I have not tried to handle the case where the user provides his own 'metavar'.  The regular class can handle that just fine.

There are too many untested edge cases to add this to production, but if anyone wants to try it, feedback will be welcomed.

This makes SUPPRESS in the subparser help behave more like SUPPRESS in the regular Action help.  Otherwise a custom 'metavar' works just as well.

----------
Added file: https://bugs.python.org/file47574/issue22848.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue22848>
_______________________________________


More information about the Python-bugs-list mailing list