From 7ea7455f094250dbb5993d565df60522568aa298 Mon Sep 17 00:00:00 2001 From: Vince Jankovics Date: Thu, 24 Mar 2022 23:32:53 +0000 Subject: [PATCH 1/3] None parsing fixed for config --- mmcv/utils/config.py | 2 ++ tests/test_utils/test_config.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mmcv/utils/config.py b/mmcv/utils/config.py index 4f96372ae4..568efa465a 100644 --- a/mmcv/utils/config.py +++ b/mmcv/utils/config.py @@ -638,6 +638,8 @@ def _parse_int_float_bool(val): pass if val.lower() in ['true', 'false']: return True if val.lower() == 'true' else False + if val.lower() == 'none': + return None return val @staticmethod diff --git a/tests/test_utils/test_config.py b/tests/test_utils/test_config.py index 6f9f95726c..126787eaa4 100644 --- a/tests/test_utils/test_config.py +++ b/tests/test_utils/test_config.py @@ -471,8 +471,19 @@ def test_dict_action(): parser.parse_args(['--options', 'item2.a=[(a,b), [1,2], false']) # Normal values args = parser.parse_args( - ['--options', 'item2.a=1', 'item2.b=0.1', 'item2.c=x', 'item3=false']) - out_dict = {'item2.a': 1, 'item2.b': 0.1, 'item2.c': 'x', 'item3': False} + ['--options', + 'item2.a=1', + 'item2.b=0.1', + 'item2.c=x', + 'item3=false', + 'item4=none', + ]) + out_dict = {'item2.a': 1, + 'item2.b': 0.1, + 'item2.c': 'x', + 'item3': False, + 'item4': None, + } assert args.options == out_dict cfg_file = osp.join(data_path, 'config/a.py') cfg = Config.fromfile(cfg_file) From 2b699adf3cefc5ca305112dd58ce357a2621b615 Mon Sep 17 00:00:00 2001 From: Vince Jankovics Date: Thu, 24 Mar 2022 23:35:23 +0000 Subject: [PATCH 2/3] Formatting --- tests/test_utils/test_config.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/test_utils/test_config.py b/tests/test_utils/test_config.py index 126787eaa4..3aec99995e 100644 --- a/tests/test_utils/test_config.py +++ b/tests/test_utils/test_config.py @@ -470,20 +470,17 @@ def test_dict_action(): with pytest.raises(AssertionError): parser.parse_args(['--options', 'item2.a=[(a,b), [1,2], false']) # Normal values - args = parser.parse_args( - ['--options', - 'item2.a=1', - 'item2.b=0.1', - 'item2.c=x', - 'item3=false', - 'item4=none', - ]) - out_dict = {'item2.a': 1, - 'item2.b': 0.1, - 'item2.c': 'x', - 'item3': False, - 'item4': None, - } + args = parser.parse_args([ + '--options', 'item2.a=1', 'item2.b=0.1', 'item2.c=x', 'item3=false', + 'item4=none' + ]) + out_dict = { + 'item2.a': 1, + 'item2.b': 0.1, + 'item2.c': 'x', + 'item3': False, + 'item4': None, + } assert args.options == out_dict cfg_file = osp.join(data_path, 'config/a.py') cfg = Config.fromfile(cfg_file) From a42342f45fe9d3bdc7d970ba48a3cfaff387110b Mon Sep 17 00:00:00 2001 From: Vince Jankovics Date: Wed, 13 Apr 2022 13:19:19 +0100 Subject: [PATCH 3/3] Lower case none fix --- mmcv/utils/config.py | 2 +- tests/test_utils/test_config.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mmcv/utils/config.py b/mmcv/utils/config.py index 568efa465a..473bd1e165 100644 --- a/mmcv/utils/config.py +++ b/mmcv/utils/config.py @@ -638,7 +638,7 @@ def _parse_int_float_bool(val): pass if val.lower() in ['true', 'false']: return True if val.lower() == 'true' else False - if val.lower() == 'none': + if val == 'None': return None return val diff --git a/tests/test_utils/test_config.py b/tests/test_utils/test_config.py index 3aec99995e..368016e572 100644 --- a/tests/test_utils/test_config.py +++ b/tests/test_utils/test_config.py @@ -472,14 +472,15 @@ def test_dict_action(): # Normal values args = parser.parse_args([ '--options', 'item2.a=1', 'item2.b=0.1', 'item2.c=x', 'item3=false', - 'item4=none' + 'item4=none', 'item5=None' ]) out_dict = { 'item2.a': 1, 'item2.b': 0.1, 'item2.c': 'x', 'item3': False, - 'item4': None, + 'item4': 'none', + 'item5': None, } assert args.options == out_dict cfg_file = osp.join(data_path, 'config/a.py')