diff --git a/CHANGELOG.md b/CHANGELOG.md index bc616f4..660814d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.2.1 (2024-01-09) + +### Fix + +- Fix return types in pydantic validation methods + ## v0.2.0 ### Features diff --git a/pyproject.toml b/pyproject.toml index a9cce4c..c268db4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pysimdjson-schemaful" -version = "0.2.0" +version = "0.2.1" description = "Schema-aware pysimdjson loader for efficient parsing of large excessive inputs." authors = ["Tzoiker "] repository = "https://github.com/tzoiker/pysimdjson-schemaful" diff --git a/simdjson_schemaful/__version__.py b/simdjson_schemaful/__version__.py index d3ec452..3ced358 100644 --- a/simdjson_schemaful/__version__.py +++ b/simdjson_schemaful/__version__.py @@ -1 +1 @@ -__version__ = "0.2.0" +__version__ = "0.2.1" diff --git a/simdjson_schemaful/parser.py b/simdjson_schemaful/parser.py index 02c531f..f81f325 100644 --- a/simdjson_schemaful/parser.py +++ b/simdjson_schemaful/parser.py @@ -3,7 +3,7 @@ import simdjson from simdjson import Parser -JsonType = Union[dict, list, str, int, float, bool] +JsonType = Union[Dict[Any, Any], List[Any], str, int, float, bool] Schema = Dict[Any, Any] _Dict = Dict[Any, Any] _List = List[Any] diff --git a/simdjson_schemaful/pydantic/v1.py b/simdjson_schemaful/pydantic/v1.py index ccf5b91..7fe0e89 100644 --- a/simdjson_schemaful/pydantic/v1.py +++ b/simdjson_schemaful/pydantic/v1.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, Optional, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Type, TypeVar, Union import pydantic from pydantic import schema_of @@ -10,6 +10,9 @@ from simdjson_schemaful import loads from simdjson_schemaful.parser import Schema +if TYPE_CHECKING: + Model = TypeVar("Model", bound="BaseModel") + class ModelMetaclass(pydantic.main.ModelMetaclass): def __new__(cls, *args: Any, **kwargs: Any) -> type: @@ -25,10 +28,10 @@ def __new__(cls, *args: Any, **kwargs: Any) -> type: class BaseModel(pydantic.BaseModel, metaclass=ModelMetaclass): @classmethod def parse_raw_simdjson( - cls, + cls: Type["Model"], b: Union[str, bytes], parser: Optional[Parser] = None, - ) -> "BaseModel": + ) -> "Model": try: obj = loads(b, schema=_REGISTRY[cls], parser=parser) except (ValueError, TypeError, UnicodeDecodeError) as e: diff --git a/simdjson_schemaful/pydantic/v2.py b/simdjson_schemaful/pydantic/v2.py index 325daa8..948166f 100644 --- a/simdjson_schemaful/pydantic/v2.py +++ b/simdjson_schemaful/pydantic/v2.py @@ -1,5 +1,5 @@ import json -from typing import Any, Dict, Optional, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, Type, TypeVar, Union import pydantic from pydantic import ValidationError @@ -9,6 +9,9 @@ from simdjson_schemaful import loads from simdjson_schemaful.parser import Schema +if TYPE_CHECKING: + Model = TypeVar("Model", bound="BaseModel") + class ModelMetaclass(pydantic._internal._model_construction.ModelMetaclass): def __new__(cls, *args: Any, **kwargs: Any) -> type: @@ -24,10 +27,10 @@ def __new__(cls, *args: Any, **kwargs: Any) -> type: class BaseModel(pydantic.BaseModel, metaclass=ModelMetaclass): @classmethod def model_validate_simdjson( - cls, + cls: Type["Model"], json_data: Union[str, bytes, bytearray], parser: Optional[Parser] = None, - ) -> pydantic.BaseModel: + ) -> "Model": try: obj = loads(json_data, schema=_REGISTRY[cls], parser=parser) except (ValueError, TypeError, UnicodeDecodeError) as e: