You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bpo-9625: argparse: Problem with defaults for variable nargs when using choices
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2016-06-05.08:59:16.765>labels= ['type-bug', 'library', '3.9', '3.10', '3.11']
title="argparse fails to parse [] when using choices and nargs='*'"updated_at=<Date2021-12-11.18:35:18.463>user='https://github.com/evanunderscore'
The problem appears to be this block of code trying to validate value immediately after it sets it to []:
# when nargs='*' on a positional, if there were no command-line
# args, use the default if it is anything other than None
elif (not arg_strings and action.nargs == ZERO_OR_MORE and
not action.option_strings):
if action.default is not None:
value = action.default
else:
value = arg_strings
self._check_value(action, value)
The fix seems to be as simple as moving the check under if action.default is not None.
(NOTE: This would be also adequately solved by patches already attached to http://bugs.python.org/issue9625, however the minimal solution to this problem is simpler.)
I don't think that this bpo-27227 and bpo-9625 are the same (although they may have the same root cause, and I would be in favour of fixing both issues). At least, I think the unit test are distinct:
This bpo-27227 is that argparse does not accept 0 options is '0 or more' are specified in nargs. bpo-9625 is that argparse returns a different type if a default is specified or when it is not.
So I propose to reopen this ticket: it is not fixed, and different from the referred ticket.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: