Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] hydra.utils.get_object method #2139

Closed
Jasha10 opened this issue Apr 9, 2022 · 0 comments · Fixed by #2520
Closed

[Feature Request] hydra.utils.get_object method #2139

Jasha10 opened this issue Apr 9, 2022 · 0 comments · Fixed by #2520
Labels
enhancement Enhanvement request
Milestone

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Apr 9, 2022

🚀 Feature Request

The hydra.utils module exposes get_class and get_method functions that can be used to look up callable objects:

>>> from hydra.utils import get_method
>>> get_method("torch.tensor")
<built-in method tensor of type object at 0x7fdbd8ff1760>

To resolve the given string, these methods use the same backend as hydra.utils.instantiate.

The get_class and get_method functions error if the given dotpath does not point to a callable:

>>> get_method("torch.double")
...
ValueError: Located non-callable of type 'dtype' while loading 'torch.double'

I think it would be useful to expose a get_object function in hydra.utils that does not give an error in this case. This would allow users to leverage Hydra's dotpath-lookup mechanism to discover arbitrary objects (rather than just callable ones).

@Jasha10 Jasha10 added the enhancement Enhanvement request label Apr 9, 2022
@Jasha10 Jasha10 added this to the Hydra 1.3.0 milestone Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhanvement request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant