[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
Changes by Vasilis Vasaitis vvasai...@gmail.com: -- nosy: +vvas ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
paul j3 added the comment: This patch fixes both help and error formatting. A module level '_format_metavars' does the formatting for both. I have tried several alternatives, including using the 'usage' style. There is similarity between this fix and that for issue 16468 (custom choices), though I don't think they conflict. In both cases, code needed to format the usage or help is also needed to help format error messages. Issue 9849 (better nargs warning) is another case where error checking in the parser depends on the formatter. In the long run we may want to refactor these issues. -- Added file: http://bugs.python.org/file35049/issue14074_1.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
paul j3 added the comment: oops - to fix the error message that OP complained about, I need to patch '_get_action_name' as well: def _get_action_name(argument): ... elif argument.metavar not in (None, SUPPRESS): metavar = argument.metavar if isinstance(metavar, tuple): metavar = '|'.join(metavar) return metavar -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
Changes by paul j3 ajipa...@gmail.com: -- nosy: +paul.j3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
paul j3 added the comment: This patch fixes the problem by joining the metavar terms with '|'. So the help for the test case (adapted from an existing tuple test) looks like: usage: PROG [-h] W1 [W2 ...] [X1 [X2 ...]] Y1 Y2 Y3 [Z1] positional arguments: W1|W2 w X1|X2 x Y1|Y2|Y3y Z1 z Alternatives include: - use ',',' ',or '/' instead of '|' - use just the 1st item of the tuple - use the default (non-tuple) metavar in the help line These all pass existing tests. The last alternative would use: #metavar = '|'.join(metavar) if len(metavar)1: metavar = default else: metavar = metavar[0] -- keywords: +patch Added file: http://bugs.python.org/file31042/issue14074.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
Steven Bethard steven.beth...@gmail.com added the comment: Looks like the problem is that _format_action_invocation is not being as careful with the different possibilities for metavar as _format_args is. Patches welcome! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14074] argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple
Changes by Tshepang Lekhonkhobe tshep...@gmail.com: -- title: argparse does not allow nargs1 for positional arguments but doesn't allow metavar to be a tuple - argparse allows nargs1 for positional arguments but doesn't allow metavar to be a tuple ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14074 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com