mirror of
https://github.com/open-mmlab/mmengine.git
synced 2025-06-03 21:54:44 +08:00
[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
This commit is contained in:
parent
5580542666
commit
6ebb7ed481
@ -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)
|
||||
|
4
tests/data/config/py_config/test_py_modify_key.py
Normal file
4
tests/data/config/py_config/test_py_modify_key.py
Normal file
@ -0,0 +1,4 @@
|
||||
# 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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user