diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 66dad61..48e6e1e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup python3.11 + - name: Setup python3.12 uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - run: python -m pip install poetry==1.6 - run: poetry install - run: poetry run ruff simdjson_schemaful tests diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 37fc080..96555d5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,10 +13,10 @@ jobs: contents: read steps: - uses: actions/checkout@v4 - - name: Setup python3.11 + - name: Setup python3.12 uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - name: Install poetry run: python -m pip install poetry diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4761544..ad8c884 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ jobs: - '3.9' - '3.10' - '3.11' + - '3.12' steps: - uses: actions/checkout@v4 - name: Setup python${{ matrix.python }} diff --git a/Makefile b/Makefile index 2c8d456..0d1c41e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROJECT_NAME := simdjson_schemaful -PROJECT_PATH := $(PROJECT_PATH) +PROJECT_PATH := $(PROJECT_NAME) PYTHON_IMAGE := docker.io/snakepacker/python:all all: diff --git a/pyproject.toml b/pyproject.toml index c268db4..a6e522a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python", "Topic :: Internet", @@ -46,12 +47,13 @@ name = "pypi" priority = "primary" [tool.poetry.dependencies] -python = ">=3.8,<3.12" +python = ">=3.8,<3.13" pysimdjson = [ - {version=">=2,<6", python=">=3.8,<3.9"}, - {version=">=3,<6", python=">=3.9,<3.11"}, + {version=">=2,<7", python=">=3.8,<3.9"}, + {version=">=3,<7", python=">=3.9,<3.11"}, # version 4 does not build for 3.11 for some reason - {version=">=3,!=4.*,<6", python=">=3.11,<3.12"}, + {version=">=3,!=4.*,<7", python=">=3.11,<3.12"}, + {version=">=6,<7", python=">=3.12,<3.13"}, ] pydantic = { version = ">=1,<3", optional = true } diff --git a/simdjson_schemaful/pydantic/v2.py b/simdjson_schemaful/pydantic/v2.py index 948166f..3d19747 100644 --- a/simdjson_schemaful/pydantic/v2.py +++ b/simdjson_schemaful/pydantic/v2.py @@ -1,5 +1,5 @@ import json -from typing import TYPE_CHECKING, Any, Dict, Optional, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, Type, TypeVar, Union import pydantic from pydantic import ValidationError @@ -38,10 +38,16 @@ def model_validate_simdjson( return cls.model_validate(obj) -class TypeAdapter(pydantic.TypeAdapter[T]): +class TypeAdapter(Generic[T]): + __slots__ = ("_ta", "_simdjson_schema") + def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self._simdjson_schema = self.json_schema() + self._ta = pydantic.TypeAdapter[T](*args, **kwargs) + self._simdjson_schema = self._ta.json_schema() + + @property + def pydantic_type_adapter(self) -> pydantic.TypeAdapter[T]: + return self._ta def _build_error(self, exc: Exception, data: Union[str, bytes]) -> ValidationError: if isinstance(exc, UnicodeDecodeError): @@ -58,7 +64,10 @@ def _build_error(self, exc: Exception, data: Union[str, bytes]) -> ValidationErr "loc": ("__root__",), "input": data, } - return ValidationError.from_exception_data(self.core_schema["type"], [details]) + return ValidationError.from_exception_data( + self._ta.core_schema["type"], + [details], + ) def validate_simdjson( self, @@ -72,4 +81,4 @@ def validate_simdjson( obj = loads(data, schema=self._simdjson_schema, parser=parser) except (ValueError, TypeError, UnicodeDecodeError) as e: raise self._build_error(e, data) - return self.validate_python(obj, strict=strict, context=context) + return self._ta.validate_python(obj, strict=strict, context=context) diff --git a/tox.ini b/tox.ini index dfc8386..c9f5aed 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,17 @@ [tox] isolated_build = True -envlist = py{38}-pydantic{1,2}-pysimdjson{2,3,4,5},\ - py{39,310}-pydantic{1,2}-pysimdjson{3,4,5},\ - py{311}-pydantic{1,2}-pysimdjson{3,5} +envlist = py{38}-pydantic{1,2}-pysimdjson{2,3,4,5,6},\ + py{39,310}-pydantic{1,2}-pysimdjson{3,4,5,6},\ + py{311}-pydantic{1,2}-pysimdjson{3,5,6},\ + py{312}-pydantic{1,2}-pysimdjson{6} toxworkdir = {env:TOXDIR:.tox} labels = - py38 = py38-pydantic{1,2}-pysimdjson{2,3,4,5} - py39 = py39-pydantic{1,2}-pysimdjson{3,4,5} - py310 = py310-pydantic{1,2}-pysimdjson{3,4,5} - py311 = py311-pydantic{1,2}-pysimdjson{3,5} + py38 = py38-pydantic{1,2}-pysimdjson{2,3,4,5,6} + py39 = py39-pydantic{1,2}-pysimdjson{3,4,5,6} + py310 = py310-pydantic{1,2}-pysimdjson{3,4,5,6} + py311 = py311-pydantic{1,2}-pysimdjson{3,5,6} + py312 = py312-pydantic{1,2}-pysimdjson{6} [testenv] passenv= @@ -26,6 +28,7 @@ deps = pysimdjson3: pysimdjson~=3.0 pysimdjson4: pysimdjson~=4.0 pysimdjson5: pysimdjson~=5.0 + pysimdjson6: pysimdjson~=6.0 commands = pytest tests