mirror of https://github.com/open-mmlab/mmcv.git
[Enhancement] Support None in DictAction (#1834)
* None parsing fixed for config * Formatting * Lower case none fixpull/1890/head
parent
6f6b17e65f
commit
b80447707c
|
@ -638,6 +638,8 @@ class DictAction(Action):
|
|||
pass
|
||||
if val.lower() in ['true', 'false']:
|
||||
return True if val.lower() == 'true' else False
|
||||
if val == 'None':
|
||||
return None
|
||||
return val
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -470,9 +470,18 @@ 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'])
|
||||
out_dict = {'item2.a': 1, 'item2.b': 0.1, 'item2.c': 'x', 'item3': False}
|
||||
args = parser.parse_args([
|
||||
'--options', '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
|
||||
cfg_file = osp.join(data_path, 'config/a.py')
|
||||
cfg = Config.fromfile(cfg_file)
|
||||
|
|
Loading…
Reference in New Issue