Skip to content

Commit 05b9d31

Browse files
authored
[DLMED] enhance load_files (#4192)
Signed-off-by: Nic Ma <[email protected]>
1 parent df177fd commit 05b9d31

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

monai/bundle/config_parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,24 @@ def load_config_file(cls, filepath: PathLike, **kwargs):
338338
raise ValueError(f"only support JSON or YAML config file so far, got name {_filepath}.")
339339

340340
@classmethod
341-
def load_config_files(cls, files: Union[PathLike, Sequence[PathLike], dict], **kwargs) -> dict:
341+
def load_config_files(cls, files: Union[PathLike, Sequence[PathLike], dict], **kwargs) -> Dict:
342342
"""
343343
Load config files into a single config dict.
344+
The latter config file in the list will override or add the former config file.
345+
``"#"`` in the config keys are interpreted as special characters to go one level
346+
further into the nested structures.
344347
345348
Args:
346349
files: path of target files to load, supported postfixes: `.json`, `.yml`, `.yaml`.
347350
kwargs: other arguments for ``json.load`` or ```yaml.safe_load``, depends on the file format.
348351
"""
349352
if isinstance(files, dict): # already a config dict
350353
return files
351-
content = {}
354+
parser = ConfigParser(config={})
352355
for i in ensure_tuple(files):
353-
content.update(cls.load_config_file(i, **kwargs))
354-
return content
356+
for k, v in (cls.load_config_file(i, **kwargs)).items():
357+
parser[k] = v
358+
return parser.get() # type: ignore
355359

356360
@classmethod
357361
def export_config_file(cls, config: Dict, filepath: PathLike, fmt="json", **kwargs):

0 commit comments

Comments
 (0)