Skip to content

Commit 34fb834

Browse files
committed
process list of strings for nargs default args
1 parent e071225 commit 34fb834

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/argparse.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,11 +2237,16 @@ def consume_positionals(start_index):
22372237
# twice (which may fail) if the argument was given, but
22382238
# only if it was defined already in the namespace
22392239
if (action.default is not None and
2240-
isinstance(action.default, str) and
22412240
hasattr(namespace, action.dest) and
22422241
action.default is getattr(namespace, action.dest)):
2243-
setattr(namespace, action.dest,
2242+
if isinstance(action.default, str):
2243+
setattr(namespace, action.dest,
22442244
self._get_value(action, action.default))
2245+
elif (action.nargs not in (OPTIONAL, None) and
2246+
isinstance(action.default, (list, tuple)) and
2247+
all(isinstance(v, str) for v in action.default)):
2248+
setattr(namespace, action.dest,
2249+
[self._get_value(action, v) for v in action.default])
22452250

22462251
if required_actions:
22472252
raise ArgumentError(None, _('the following arguments are required: %s') %

0 commit comments

Comments
 (0)