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 <>
I would love to get this issue resolved; it seems like everyone agrees that it's a bug. It came up for me recently: 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, 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()

if __name__ == '__main__':

Which yields:
$ python 
Namespace(foo=[-1], bar=-1, pos=-1)
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: <>
2020-07-29 18:22:56jameshcorbettlinkissue9625 messages
2020-07-29 18:22:56jameshcorbettcreate