[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:
Mashiro 2022-08-08 17:07:47 +08:00 committed by GitHub
parent 5580542666
commit 6ebb7ed481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

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

View File

@ -0,0 +1,4 @@
# Copyright (c) OpenMMLab. All rights reserved.
# Support modify value in config.
item1 = dict()
item1['a'] = 1

View File

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