Skip to content

Commit 3b2ae11

Browse files
committed
add utils._RequireAttrsABCMeta
1 parent e8dfd93 commit 3b2ae11

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

adaptive/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import abc
34
import functools
45
import gzip
56
import os
@@ -67,3 +68,14 @@ def decorator(method):
6768
return functools.wraps(other)(method)
6869

6970
return decorator
71+
72+
73+
class _RequireAttrsABCMeta(abc.ABCMeta):
74+
required_attributes = []
75+
76+
def __call__(self, *args, **kwargs):
77+
obj = super().__call__(*args, **kwargs)
78+
for name in obj.required_attributes:
79+
if not hasattr(obj, name):
80+
raise ValueError(f"Required attribute {name} not set in __init__.")
81+
return obj

0 commit comments

Comments
 (0)