Add angle brackets for required args in argparse

scruel tao scruelt at hotmail.com
Wed Feb 22 21:43:23 EST 2023


Thank you for your workarounds, Mark Bourne.
`metavar` argument should be sufficient  for infrequent use scenarios, and I will consider to use the custom help formatter if necessary.

>>> That's a bit closer to what you asked for, since the required argument
>>> shown in the error message doesn't include the angle brackets.  It also
>>> avoids needing to specify a `metavar` for every positional argument.
>>> However, it is overriding a non-public method of the `HelpFormatter`
>>> class, so might not work across all Python versions if the name or
>>> signature of that method changes (even if it does work with all current
>>> versions, it might break in future).

Your are right to be concerned, that’s why I still think, might the `argparse` can provide a more stable way which can set such format strategy globally, your workarounds are fine to work now, just I have to write the same code to parse either `metaver` or `formatter` every times I use argparse.
Might can have different argparse subclasses, or make some HelpFormatter builtin, so that users won’t need to write them by themselves.


More information about the Python-list mailing list