From 705af2e8b53cd269b8dab96e9acc56bbdae215dd Mon Sep 17 00:00:00 2001 From: bw2 Date: Thu, 23 Apr 2020 11:56:24 -0400 Subject: [PATCH 1/2] Fix bug in accepts_list_and_has_nargs section. --- configargparse.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/configargparse.py b/configargparse.py index cf661be..46ddbd6 100644 --- a/configargparse.py +++ b/configargparse.py @@ -741,11 +741,11 @@ 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: @@ -755,7 +755,7 @@ def convert_item_to_command_line_arg(self, action, key, value): 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) ) From fd71c7e74c0b652428a1bcc52127d198a6b62d7d Mon Sep 17 00:00:00 2001 From: bw2 Date: Thu, 23 Apr 2020 12:00:46 -0400 Subject: [PATCH 2/2] Update configargparse.py --- configargparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configargparse.py b/configargparse.py index 46ddbd6..4e718ea 100644 --- a/configargparse.py +++ b/configargparse.py @@ -749,7 +749,7 @@ def convert_item_to_command_line_arg(self, action, key, value): 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))