Message180049
The exception question is messy, but I think it is the wrong question. The doc is correct in that it says what the code should be doing. To test whether an argument is in a collection of choices, the code should just say that: 'arg in choices' (as far as I know, it does -- for the actual check). In other words, I think the original intent of this issue is correct.
"Clearly the module was written under the assumption (in multiple places) that choices are iterable." I think it should not. We implement 'in' with '__contains__', rather than forcing the use of iteration, for good reason. I discussed some examples in msg175520.
As far as I know, the reason argparse iterates is to bypass the object's representation methods and produce custom, one-size-fits-all, usage and error messages. As discussed in #16418, this supposed user-friendliness may not be. To me, restricting input for this reason is a tail-wags-dog situation. If the object is not iterable, just use repr for the messages instead of exiting. Let the app writer be responsible for making them user-friendly and not absurdly long. |
|
Date |
User |
Action |
Args |
2013-01-15 20:24:11 | terry.reedy | set | recipients:
+ terry.reedy, bethard, r.david.murray, chris.jerdonek, wim.glenn |
2013-01-15 20:24:11 | terry.reedy | set | messageid: <1358281451.32.0.993449826824.issue16468@psf.upfronthosting.co.za> |
2013-01-15 20:24:11 | terry.reedy | link | issue16468 messages |
2013-01-15 20:24:10 | terry.reedy | create | |
|