Skip to content

Commit ad88bb3

Browse files
committed
Disable base class initialization
Signed-off-by: Samuel Monson <[email protected]>
1 parent d8032e7 commit ad88bb3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/guidellm/utils/pydantic_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ class DatabaseConfig(BaseConfig):
275275

276276
schema_discriminator: ClassVar[str] = "model_type"
277277

278+
def __new__(cls, *args, **kwargs): # noqa: ARG004
279+
"""
280+
Prevent direct instantiation of base classes that use this mixin.
281+
282+
Only allows instantiation of concrete subclasses, not the base class.
283+
"""
284+
base_type = cls.__pydantic_schema_base_type__()
285+
if cls is base_type:
286+
raise TypeError(f"only children of '{cls.__name__}' may be instantiated")
287+
return super().__new__(cls)
288+
278289
@classmethod
279290
def register_decorator(
280291
cls, clazz: RegisterClassT, name: str | list[str] | None = None

0 commit comments

Comments
 (0)