This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jameshcorbett
Recipients Jan Hutař, Sworddragon, berker.peksag, bethard, ced, eric.araujo, eric.smith, jameshcorbett, lanzz, macfreek, paul.j3, regis, rhettinger, sebix, thesociable
Date 2020-07-29.18:22:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596046976.69.0.509196250414.issue9625@roundup.psfhosted.org>
In-reply-to
Content
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)
```
History
Date User Action Args
2020-07-29 18:22:56jameshcorbettsetrecipients: + jameshcorbett, rhettinger, bethard, macfreek, eric.smith, eric.araujo, ced, Sworddragon, thesociable, regis, berker.peksag, paul.j3, sebix, lanzz, Jan Hutař
2020-07-29 18:22:56jameshcorbettsetmessageid: <1596046976.69.0.509196250414.issue9625@roundup.psfhosted.org>
2020-07-29 18:22:56jameshcorbettlinkissue9625 messages
2020-07-29 18:22:56jameshcorbettcreate