[issue16468] argparse only supports iterable choices

Chris Jerdonek report at bugs.python.org
Wed Nov 14 17:25:44 CET 2012


Chris Jerdonek added the comment:

For the record, choices types implementing only __contains__ never worked in any cases.  (I should have said ArgumentParser.add_argument() raises a ValueError in the above.)

So I wonder if we should classify this as an enhancement and simply document the restriction in maintenance releases to iterable types.  Clearly the module was written under the assumption (in multiple places) that choices are iterable.

Also, if we do change this, perhaps we should fall back to displaying the metavar in help messages when naming the container rather than using repr().  A message like the following, for example, wouldn't be very helpful or look very good:

   invalid choice: 0 (choose from <__main__.Container object at 0x10555efb0>)

I think we should avoid letting Python creep into help and usage text.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16468>
_______________________________________


More information about the Python-bugs-list mailing list