-
This seems like a dumb question, but how do I resolve a string like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @greaber! >>> import hydra
>>> assert hydra.utils.get_method("functools.lru_cache") is __import__("functools").lru_cache The I do sometimes find myself using an omegaconf resolver that calls Python's >>> from omegaconf import OmegaConf
>>> OmegaConf.register_new_resolver("eval", eval)
>>> yaml_data = """foo: '${eval:"bytes(123)"}'"""
>>> assert OmegaConf.create(yaml_data).foo == bytes(123) To register this resolver would be unsafe if there's a chance that your DictConfig object will contain untrusted 3rd party data, as the 3rd party could inject some things to be eval'd on your machine. (The same caveat applies by-and-large to calling Hydra's |
Beta Was this translation helpful? Give feedback.
Hi @greaber!
There are the super-useful
hydra.utils.get_class
andhydra.utils.get_method
functions. They are undocumented currently, but that should change soon.The
get_class
function allows looking up any class (i.e. any instance oftype
), and throws aValueError
if the looked-up object is not atype
. Meanwhile,get_method
does the same thing, except it allows looking up anycallable
object. There is a feature request open to add ahydra.utils.get_object
method that would do the same thing but without the restriction that the looked-up object must be atype
/callable
. Please giv…