Skip to content

Commit 4fbcfa9

Browse files
Revert to using _union_cache attribute
1 parent e82792d commit 4fbcfa9

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/oqd_dataschema/base.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def validate_data_matches_shape_dtype(self):
147147
class GroupRegistry:
148148
"""Registry for managing group types dynamically"""
149149

150-
_types: Dict[str, Type[Group]] = {}
150+
_types: dict[str, Type[Group]] = {}
151+
_union_cache = None
151152

152153
@classmethod
153154
def register(cls, group_type: Type[Group]):
@@ -168,24 +169,22 @@ def register(cls, group_type: Type[Group]):
168169
)
169170

170171
cls._types[type_name] = group_type
171-
172-
@classmethod
173-
@property
174-
def union_cache(cls):
175-
"""Get the current Union of all registered types (computed on demand)"""
176-
if not cls._types:
177-
raise ValueError("No group types registered")
178-
179-
type_list = list(cls._types.values())
180-
if len(type_list) == 1:
181-
return type_list[0]
182-
else:
183-
return Union[tuple(type_list)]
172+
cls._union_cache = None # Invalidate cache
184173

185174
@classmethod
186175
def get_union(cls):
187176
"""Get the current Union of all registered types"""
188-
return cls.union_cache
177+
if cls._union_cache is None:
178+
if not cls._types:
179+
raise ValueError("No group types registered")
180+
181+
type_list = list(cls._types.values())
182+
if len(type_list) == 1:
183+
cls._union_cache = type_list[0]
184+
else:
185+
cls._union_cache = Union[tuple(type_list)]
186+
187+
return cls._union_cache
189188

190189
@classmethod
191190
def get_adapter(cls):
@@ -199,8 +198,9 @@ def get_adapter(cls):
199198
def clear(cls):
200199
"""Clear all registered types (useful for testing)"""
201200
cls._types.clear()
201+
cls._union_cache = None
202202

203203
@classmethod
204204
def list_types(cls):
205205
"""List all registered type names"""
206-
return list(cls._types.keys())
206+
return list(cls._types.keys())

0 commit comments

Comments
 (0)