Skip to content

Commit

Permalink
Merge pull request #188 from bw2/bw2-patch-2
Browse files Browse the repository at this point in the history
Fix bug in accepts_list_and_has_nargs section.
  • Loading branch information
bw2 authored Apr 24, 2020
2 parents 6b34e07 + fd71c7e commit bca6e69
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions configargparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,21 +741,21 @@ def convert_item_to_command_line_arg(self, action, key, value):
self.error("Unexpected value for %s: '%s'. Expecting 'true', "
"'false', 'yes', 'no', '1' or '0'" % (key, value))
elif isinstance(value, list):
accepts_list = ((isinstance(action, argparse._StoreAction) or
isinstance(action, argparse._AppendAction)) and
action.nargs is not None and (
action.nargs in ('+', '*')) or
(isinstance(action.nargs, int) and action.nargs > 1))
accepts_list_and_has_nargs = action is not None and action.nargs is not None and (
isinstance(action, argparse._StoreAction) or isinstance(action, argparse._AppendAction)
) and (
action.nargs in ('+', '*') or (isinstance(action.nargs, int) and action.nargs > 1)
)

if action is None or isinstance(action, argparse._AppendAction):
for list_elem in value:
if accepts_list and isinstance(list_elem, list):
if accepts_list_and_has_nargs and isinstance(list_elem, list):
args.append(command_line_key)
for sub_elem in list_elem:
args.append(str(sub_elem))
else:
args.append( "%s=%s" % (command_line_key, str(list_elem)) )
elif accepts_list:
elif accepts_list_and_has_nargs:
args.append( command_line_key )
for list_elem in value:
args.append( str(list_elem) )
Expand Down

0 comments on commit bca6e69

Please sign in to comment.