feat: add preset resolver
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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
|
||||
Reference in New Issue
Block a user