Message180068
| Author |
chris.jerdonek |
| Recipients |
chris.jerdonek |
| Date |
2013年01月16日.02:30:06 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1358303407.58.0.0453921356618.issue16977@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
When passing a string for the choices argument, argparse's usage and error messages differ from its behavior:
>>> p = argparse.ArgumentParser()
>>> p.add_argument('a', choices='abc')
>>> p.parse_args(['d'])
usage: [-h] {a,b,c}
: error: argument a: invalid choice: 'd' (choose from 'a', 'b', 'c')
>>> p.parse_args(['bc'])
Namespace(a='bc')
This is because argparse uses the "in" operator instead of sequence iteration to check whether an argument value is valid. Any resolution should also consider the behavior for string subclasses as well as perhaps bytes-like objects. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2013年01月16日 02:30:07 | chris.jerdonek | set | recipients:
+ chris.jerdonek |
| 2013年01月16日 02:30:07 | chris.jerdonek | set | messageid: <1358303407.58.0.0453921356618.issue16977@psf.upfronthosting.co.za> |
| 2013年01月16日 02:30:06 | chris.jerdonek | link | issue16977 messages |
| 2013年01月16日 02:30:06 | chris.jerdonek | create |
|