-
-
Notifications
You must be signed in to change notification settings - Fork 815
Closed
Labels
Description
The hydra.utils.instantiate function looks up it's target by using Python's importlib machinery.
# my_app.py
import hydra
hydra.utils.instantiate({"_target_": "my_module.Foo"})# my_module.py
class Foo:
print("Hi")$ python3 my_app.py
Hi
Suppose the user makes a syntax error in my_module.py, forgetting a colon in the class statement:
# my_module.py
class Foo
print("Hi")python3 my_app.py
Traceback (most recent call last):
...
ValueError: Empty module name
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
...
File "/home/jasha10/hydra.git/hydra/_internal/utils.py", line 573, in _locate
raise ImportError(f"Error loading module '{path}'") from e
ImportError: Error loading module 'my_module.Foo'
The first part of this traceback, which says "ValueError: Empty module name", is not very helpful.
The traceback should instead look like this:
$ python3 my_app.py
Traceback (most recent call last):
...
class Foo
^
SyntaxError: invalid syntax
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
...
File "/home/jasha10/hydra.git/hydra/_internal/utils.py", line 573, in _locate
raise ImportError(f"Error loading module '{path}'") from e
ImportError: Error loading module 'my_module.Foo'
Reactions are currently unavailable