You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Passing callable as instantiate_target_ fails for nested classes #1914
Hydra's instantiate function allows users to pass a callable (rather than a
string) via the _target_ keyword argument. For example:
deffn():
return"fn return"classA:
def__init__(self):
print("in A.__init__")
@classmethoddefmethod(self):
return"A.method return"# passing a callable (rather than a string) as _target_:fn_return=instantiate({}, _target_=fn)
A_instance=instantiate({}, _target_=A)
A_method_return=instantiate({}, _target_=A.method)
However, this fails when a nested class is passed as the _target_:
classA:
classB:
def__init__(self):
print("in A.B.__init__")
A_B_instance=instantiate({}, _target_=A.B) # ImportError: Encountered AttributeError while loading '__main__.B': module '__main__' has no attribute 'B'
The error message indicates that __main__.B could not be found. This indicates a mistake in handling the keyword argument _target_=A.B: it is __main__.A.B that should have been looked up, not __main__.B.
Activity