Skip to content

Resolve string to python object #2312

Answered by Jasha10
greaber asked this question in Q&A
Jul 23, 2022 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Hi @greaber!
There are the super-useful hydra.utils.get_class and hydra.utils.get_method functions. They are undocumented currently, but that should change soon.

>>> import hydra
>>> assert hydra.utils.get_method("functools.lru_cache") is __import__("functools").lru_cache

The get_class function allows looking up any class (i.e. any instance of type), and throws a ValueError if the looked-up object is not a type. Meanwhile, get_method does the same thing, except it allows looking up any callable object. There is a feature request open to add a hydra.utils.get_object method that would do the same thing but without the restriction that the looked-up object must be a type/callable. Please giv…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Jasha10
Comment options

Jasha10 Jul 23, 2022
Collaborator

@Jasha10
Comment options

Jasha10 Jul 23, 2022
Collaborator

@greaber
Comment options

Answer selected by greaber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants