import copy __all__ = ["recursive_eval"] def recursive_eval(obj, globals=None): if globals is None: globals = copy.deepcopy(obj) if isinstance(obj, dict): for key in obj: obj[key] = recursive_eval(obj[key], globals) elif isinstance(obj, list): for k, val in enumerate(obj): obj[k] = recursive_eval(val, globals) elif isinstance(obj, str) and obj.startswith("${") and obj.endswith("}"): obj = eval(obj[2:-1], globals) obj = recursive_eval(obj, globals) return obj