Unverified Commit b8044770 authored by Vince Jankovics's avatar Vince Jankovics Committed by GitHub
Browse files

[Enhancement] Support None in DictAction (#1834)

* None parsing fixed for config

* Formatting

* Lower case none fix
parent 6f6b17e6
...@@ -638,6 +638,8 @@ class DictAction(Action): ...@@ -638,6 +638,8 @@ class DictAction(Action):
pass pass
if val.lower() in ['true', 'false']: if val.lower() in ['true', 'false']:
return True if val.lower() == 'true' else False return True if val.lower() == 'true' else False
if val == 'None':
return None
return val return val
@staticmethod @staticmethod
......
...@@ -470,9 +470,18 @@ def test_dict_action(): ...@@ -470,9 +470,18 @@ def test_dict_action():
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
parser.parse_args(['--options', 'item2.a=[(a,b), [1,2], false']) parser.parse_args(['--options', 'item2.a=[(a,b), [1,2], false'])
# Normal values # Normal values
args = parser.parse_args( args = parser.parse_args([
['--options', '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',
out_dict = {'item2.a': 1, 'item2.b': 0.1, 'item2.c': 'x', 'item3': False} 'item4=none', 'item5=None'
])
out_dict = {
'item2.a': 1,
'item2.b': 0.1,
'item2.c': 'x',
'item3': False,
'item4': 'none',
'item5': None,
}
assert args.options == out_dict assert args.options == out_dict
cfg_file = osp.join(data_path, 'config/a.py') cfg_file = osp.join(data_path, 'config/a.py')
cfg = Config.fromfile(cfg_file) cfg = Config.fromfile(cfg_file)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment