Message374581
I would love to get this issue resolved; it seems like everyone agrees that it's a bug. It came up for me recently: https://bugs.python.org/issue41047. Judging from the comments above, the consensus is that the relevant line, `self._check_value(action, value)` should either be replaced with something like `if isinstance(value, collections.abc.Sequence): for v in value: self._check_value(action, v)` or be removed entirely.
I think the line should just be removed. I think it's fair to assume that users of `argparse` know what they're doing, so I think they should be allowed to pass default values that conflict with `choices`. Also, removing the line makes the behavior consistent with the optionals, which don't check whether default values are in `choices`. See the below script:
```
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--foo", nargs="+", default=[-1], choices=range(10))
parser.add_argument("--bar", nargs="*", default=-1, choices=range(10))
parser.add_argument("pos", nargs="?", default=-1, choices=range(10))
args = parser.parse_args()
print(args)
if __name__ == '__main__':
main()
```
Which yields:
```
$ python argparse_test.py
Namespace(foo=[-1], bar=-1, pos=-1)
``` |
|
Date |
User |
Action |
Args |
2020-07-29 18:22:56 | jameshcorbett | set | recipients:
+ jameshcorbett, rhettinger, bethard, macfreek, eric.smith, eric.araujo, ced, deleted250130, thesociable, regis, berker.peksag, paul.j3, sebix, lanzz, Jan Hutař |
2020-07-29 18:22:56 | jameshcorbett | set | messageid: <1596046976.69.0.509196250414.issue9625@roundup.psfhosted.org> |
2020-07-29 18:22:56 | jameshcorbett | link | issue9625 messages |
2020-07-29 18:22:56 | jameshcorbett | create | |
|