From 9f49c27c97cc6325669a2dd9289169d8d7af83a5 Mon Sep 17 00:00:00 2001 From: MaxST Date: Mon, 16 Dec 2024 01:26:21 +0300 Subject: [PATCH] :green_heart: Fix CI. --- .github/workflows/pr.yml | 2 +- apiclient_pydantic/serializers.py | 18 +++++++++++------- pyproject.toml | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f5647a9..20b8f43 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -11,7 +11,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] fail-fast: false steps: - uses: actions/checkout@v4 diff --git a/apiclient_pydantic/serializers.py b/apiclient_pydantic/serializers.py index dc34ec2..748d963 100644 --- a/apiclient_pydantic/serializers.py +++ b/apiclient_pydantic/serializers.py @@ -1,7 +1,8 @@ +from __future__ import annotations + import inspect -from collections.abc import Awaitable from functools import partial -from typing import Annotated, Any, Callable, Optional, TypeVar, Union, cast +from typing import TYPE_CHECKING, Annotated, Any, Callable, TypeVar, cast from apiclient import APIClient from pydantic import AfterValidator, BaseModel, ConfigDict @@ -16,6 +17,9 @@ from pydantic.plugin._schema_validator import create_schema_validator from pydantic.validate_call_decorator import _check_function_type +if TYPE_CHECKING: + from collections.abc import Awaitable + T = TypeVar('T', bound=APIClient) AnyCallableT = TypeVar('AnyCallableT', bound=Callable[..., Any]) TModel = TypeVar('TModel', bound=BaseModel) @@ -72,12 +76,12 @@ async def return_val_wrapper(aw: Awaitable[Any]) -> None: def serialize( - __func: Optional[AnyCallableT] = None, + __func: AnyCallableT | None = None, /, *, - config: Optional[ConfigDict] = None, + config: ConfigDict | None = None, validate_return: bool = True, - response: Optional[type[BaseModel]] = None, + response: type[BaseModel] | None = None, ) -> AnyCallableT | Callable[[AnyCallableT], AnyCallableT]: parent_namespace = _typing_extra.parent_frame_namespace() @@ -98,8 +102,8 @@ def validate(function: AnyCallableT) -> AnyCallableT: def serialize_all_methods( - __cls: Optional[type[T]] = None, /, *, config: Optional[ConfigDict] = None -) -> Union[AnyCallableT, Callable[[AnyCallableT], AnyCallableT], Callable[[type[T]], type[T]]]: + __cls: type[T] | None = None, /, *, config: ConfigDict | None = None +) -> AnyCallableT | Callable[[AnyCallableT], AnyCallableT] | Callable[[type[T]], type[T]]: def decorate(cls: type[T]) -> type[T]: for attr, value in vars(cls).items(): if not attr.startswith('_') and inspect.isfunction(value) and attr not in APICLIENT_METHODS: diff --git a/pyproject.toml b/pyproject.toml index 557731e..1494307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -175,6 +175,7 @@ fail_under = 100 show_missing = true exclude_lines = [ "pragma: no cover", + "if TYPE_CHECKING:", "raise AssertionError", "raise NotImplementedError", "if __name__ == .__main__.:",