Chris Jerdonek added the comment:
Attaching patch. With this patch, passing a non-iterable choices argument to
parser.add_argument() raises (for example):
Traceback (most recent call last):
...
File ".../Lib/argparse.py", line 558, in _metavar_formatter
choice_strs = [str(choice) for choice in action.choices]
TypeError: 'MyChoices' object is not iterable
instead of the incorrect:
File ".../Lib/argparse.py", line 1333, in add_argument
raise ValueError("length of metavar tuple does not match nargs")
ValueError: length of metavar tuple does not match nargs
Is it okay to change this exception type in maintenance releases? The other
option is to keep the error as a ValueError but to change the error message,
though I think TypeError is the correct exception to allow through. Note that
the existing ValueError is preserved for other code paths. Indeed, there are
several tests checking for this ValueError and its error message, which the
attached patch does not break.
If we want to consider accepting non-iterable choices for 3.4, we can still
have that discussion as part of a separate patch.
----------
stage: needs patch -> patch review
Added file: http://bugs.python.org/file28734/issue-16468-2.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue16468>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com