Skip to content
Snippets Groups Projects
Unverified Commit 6ebb7ed4 authored by Mashiro's avatar Mashiro Committed by GitHub
Browse files

[Fix] Fix config cannot change(assign) the value of the dict in config(without base config) (#378)

* Support changing value of dict in config(without base config)

* minor refine
parent 55805426
No related branches found
No related tags found
No related merge requests found
......@@ -481,6 +481,7 @@ class Config:
def is_base_line(c):
return (isinstance(c, ast.Assign)
and isinstance(c.targets[0], ast.Name)
and c.targets[0].id == BASE_KEY)
base_code = next((c for c in codes if is_base_line(c)), None)
......
# Copyright (c) OpenMMLab. All rights reserved.
# Support modify value in config.
item1 = dict()
item1['a'] = 1
......@@ -658,6 +658,13 @@ class TestConfig:
assert cfg['item1'] == 1
assert cfg['item2'] == 2
# Test support modifying the value of dict without defining base
# config.
cfg_file = osp.join(self.data_path,
'config/py_config/test_py_modify_key.py')
cfg = Config._file2dict(cfg_file)[0]
assert cfg == dict(item1=dict(a=1))
def _merge_recursive_bases(self):
cfg_file = osp.join(self.data_path,
'config/py_config/test_merge_recursive_bases.py')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment