James Corbett <james.h.corb...@gmail.com> added the comment:
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) ``` ---------- nosy: +jameshcorbett _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue9625> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com