We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 36d5ee7 commit 2b89d7bCopy full SHA for 2b89d7b
1 file changed
adaptive/utils.py
@@ -74,11 +74,12 @@ class _RequireAttrsABCMeta(abc.ABCMeta):
74
def __call__(self, *args, **kwargs):
75
obj = super().__call__(*args, **kwargs)
76
for name, type_ in obj.__annotations__.items():
77
- if not hasattr(obj, name):
78
- raise ValueError(f"Required attribute {name} not set in __init__.")
79
- elif not isinstance(getattr(obj, name), type_):
80
- raise TypeError(
81
- f"The attribute '{name}' is of {type_} instead of {type(getattr(obj, name))}"
82
- )
83
-
+ try:
+ x = getattr(obj, name)
+ if not isinstance(x, type_):
+ raise TypeError(
+ f"The attribute '{name}' is of {type_} instead of {type(x)}."
+ )
+ except AttributeError as e:
84
+ raise e(f"Required attribute {name} not set in __init__.")
85
return obj
0 commit comments