[Enhancement] Support None in DictAction (#1834)

* None parsing fixed for config

* Formatting

* Lower case none fix
pull/1890/head
Vince Jankovics 2022-04-18 07:44:32 +01:00 committed by GitHub
parent 6f6b17e65f
commit b80447707c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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)