29 lines
608 B
Python
29 lines
608 B
Python
import importlib
|
|
|
|
__all__ = (
|
|
"reflect",
|
|
"merge_dicts",
|
|
)
|
|
|
|
|
|
def reflect(value: str):
|
|
if ":" in value:
|
|
module_name, item_name = value.split(":")
|
|
else:
|
|
module_name, item_name = "builtins", value
|
|
module = importlib.import_module(module_name)
|
|
return getattr(module, item_name)
|
|
|
|
|
|
def merge_dicts(target, enhancer):
|
|
for key, val in enhancer.items():
|
|
if key not in target:
|
|
target[key] = val
|
|
continue
|
|
|
|
if isinstance(val, dict):
|
|
merge_dicts(target[key], val)
|
|
else:
|
|
target[key] = val
|
|
return target
|