From b7fbff4a87e102d382ab3db83c3c39a924fc2fac Mon Sep 17 00:00:00 2001 From: Tzoiker Date: Tue, 9 Jan 2024 16:00:31 +0300 Subject: [PATCH 1/3] fix: typing --- simdjson_schemaful/pydantic/v1.py | 9 ++++++--- simdjson_schemaful/pydantic/v2.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) 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: From a595729b938a98d467828d8dba0328e73157c583 Mon Sep 17 00:00:00 2001 From: Tzoiker Date: Tue, 9 Jan 2024 16:02:30 +0300 Subject: [PATCH 2/3] chore: bump version --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- simdjson_schemaful/__version__.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) 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" From cce8829ce33bd58686f00ed3937ecd88ee5307af Mon Sep 17 00:00:00 2001 From: Tzoiker Date: Tue, 9 Jan 2024 16:23:07 +0300 Subject: [PATCH 3/3] style: fix linter error --- simdjson_schemaful/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]