import error message in get_class
This commit is contained in:
@@ -248,13 +248,16 @@ def get_class(spec):
|
||||
a class (or any object) and optionally names of attributes
|
||||
:return: the object
|
||||
"""
|
||||
error = None
|
||||
for maxsplit in range(1, len(spec)):
|
||||
# len(spec) is high enough for all cases
|
||||
module, *attrs = spec.rsplit('.', maxsplit)
|
||||
try:
|
||||
obj = importlib.import_module(module)
|
||||
break
|
||||
except ImportError:
|
||||
except ImportError as e:
|
||||
if error is None:
|
||||
error = module, e
|
||||
if '.' in module:
|
||||
continue
|
||||
raise
|
||||
@@ -262,7 +265,8 @@ def get_class(spec):
|
||||
try:
|
||||
obj = getattr(obj, attr)
|
||||
except AttributeError:
|
||||
print(na, attrs)
|
||||
if error is not None:
|
||||
raise ImportError(f'{error[1]} during import {error[0]}') from None
|
||||
raise AttributeError(f'{".".join(attrs[:na+1])!r} not found in {module!r}') from None
|
||||
return obj
|
||||
|
||||
|
||||
Reference in New Issue
Block a user