diff --git a/src/lmstudio/schemas.py b/src/lmstudio/schemas.py index 992c802..db62fbc 100644 --- a/src/lmstudio/schemas.py +++ b/src/lmstudio/schemas.py @@ -90,6 +90,12 @@ class BaseModel(Struct, omit_defaults=True, kw_only=True): # Allows structured predictions using a `pydantic.BaseModel` inspired format, # even in applications that don't otherwise depend on Pydantic + def __init_subclass__(cls, *args: Any, **kwds: Any) -> None: + # Eagerly populate annotations on Python 3.14+ + # Workaround for https://github.com/lmstudio-ai/lmstudio-python/issues/153 + cls.__annotations__ + super().__init_subclass__() + @classmethod def model_json_schema(cls) -> DictSchema: """Returns JSON Schema dict describing the format of this class.""" @@ -186,6 +192,12 @@ class LMStudioStruct(Generic[TWireFormat], Struct, omit_defaults=True, kw_only=T # * Allow non-default fields after default fields # + def __init_subclass__(cls, *args: Any, **kwds: Any) -> None: + # Eagerly populate annotations on Python 3.14+ + # Workaround for https://github.com/lmstudio-ai/lmstudio-python/issues/153 + cls.__annotations__ + super().__init_subclass__(*args, **kwds) + # This is actually defined in msgspec.Struct, # but is missing from the published type stubs: # https://github.com/jcrist/msgspec/pull/813 diff --git a/tests/support/__init__.py b/tests/support/__init__.py index 8648e64..fc2201d 100644 --- a/tests/support/__init__.py +++ b/tests/support/__init__.py @@ -1,8 +1,5 @@ """Common test support interfaces and expected value definitions.""" -# Work around https://github.com/jcrist/msgspec/issues/847 -from __future__ import annotations - import logging import sys diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 4c48e17..28b8e99 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -1,8 +1,5 @@ """Test schema processing support.""" -# Work around https://github.com/jcrist/msgspec/issues/847 -from __future__ import annotations - from typing import Any, Type import pytest