Skip to content

Commit b431fe3

Browse files
committed
implement Joe's suggestion
1 parent 8681b7f commit b431fe3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

adaptive/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ def __call__(self, *args, **kwargs):
7676
for name, type_ in obj.__annotations__.items():
7777
try:
7878
x = getattr(obj, name)
79-
if not isinstance(x, type_):
80-
raise TypeError(
81-
f"The attribute '{name}' is of {type_} instead of {type(x)}."
82-
)
8379
except AttributeError:
84-
raise AttributeError(f"Required attribute {name} not set in __init__.")
80+
raise AttributeError(
81+
f"Required attribute {name} not set in __init__."
82+
) from None
83+
else:
84+
if not isinstance(x, type_):
85+
msg = f"The attribute '{name}' should be of type {type_}, not {type(x)}."
86+
raise TypeError(msg)
8587
return obj

0 commit comments

Comments
 (0)