Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Support None in DictAction #1834

Merged
merged 3 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mmcv/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 'None':
return None
return val

@staticmethod
Expand Down
15 changes: 12 additions & 3 deletions tests/test_utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down