diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 484cddb..a7f9ee8 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -21,7 +21,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.8" + python-version: "3.9" cache: "pip" cache-dependency-path: pyproject.toml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b676e95..83c57f4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] pydantic-version: ["pydantic-v1", "pydantic-v2"] fail-fast: false @@ -58,7 +58,7 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.9' - name: Get coverage files uses: actions/download-artifact@v4 diff --git a/fast_depends/_compat.py b/fast_depends/_compat.py index fd2a790..c74af41 100644 --- a/fast_depends/_compat.py +++ b/fast_depends/_compat.py @@ -1,6 +1,6 @@ import sys from importlib.metadata import version as get_version -from typing import Any, Dict, Optional, Tuple, Type +from typing import Any, Optional from pydantic import BaseModel, create_model from pydantic.version import VERSION as PYDANTIC_VERSION @@ -24,17 +24,17 @@ # isort: off if PYDANTIC_V2: from pydantic import ConfigDict - from pydantic._internal._typing_extra import ( # type: ignore[no-redef] + from pydantic._internal._typing_extra import ( eval_type_lenient as evaluate_forwardref, ) - def model_schema(model: Type[BaseModel]) -> Dict[str, Any]: + def model_schema(model: type[BaseModel]) -> dict[str, Any]: return model.model_json_schema() def get_config_base(config_data: Optional[ConfigDict] = None) -> ConfigDict: return config_data or ConfigDict(**default_pydantic_config) # type: ignore[typeddict-item] - def get_aliases(model: Type[BaseModel]) -> Tuple[str, ...]: + def get_aliases(model: type[BaseModel]) -> tuple[str, ...]: return tuple(f.alias or name for name, f in model.model_fields.items()) class CreateBaseModel(BaseModel): @@ -46,13 +46,13 @@ class CreateBaseModel(BaseModel): from pydantic.typing import evaluate_forwardref as evaluate_forwardref # type: ignore[no-redef] from pydantic.config import get_config, ConfigDict, BaseConfig - def get_config_base(config_data: Optional[ConfigDict] = None) -> Type[BaseConfig]: # type: ignore[misc] + def get_config_base(config_data: Optional[ConfigDict] = None) -> type[BaseConfig]: # type: ignore[misc] return get_config(config_data or ConfigDict(**default_pydantic_config)) # type: ignore[typeddict-item] - def model_schema(model: Type[BaseModel]) -> Dict[str, Any]: + def model_schema(model: type[BaseModel]) -> dict[str, Any]: return model.schema() - def get_aliases(model: Type[BaseModel]) -> Tuple[str, ...]: + def get_aliases(model: type[BaseModel]) -> tuple[str, ...]: return tuple(f.alias or name for name, f in model.__fields__.items()) class CreateBaseModel(BaseModel): # type: ignore[no-redef] diff --git a/fast_depends/core/build.py b/fast_depends/core/build.py index b8d14ca..df9a142 100644 --- a/fast_depends/core/build.py +++ b/fast_depends/core/build.py @@ -1,21 +1,16 @@ import inspect +from collections.abc import Awaitable, Sequence from copy import deepcopy from typing import ( + Annotated, Any, - Awaitable, Callable, - Dict, - List, Optional, - Sequence, - Tuple, - Type, TypeVar, Union, ) from typing_extensions import ( - Annotated, ParamSpec, get_args, get_origin, @@ -62,18 +57,16 @@ def build_call_model( ), f"You cannot use async dependency `{name}` at sync main" typed_params, return_annotation = get_typed_signature(call) - if ( - (is_call_generator := is_gen_callable(call) or - is_async_gen_callable(call)) and - (return_args := get_args(return_annotation)) + if (is_call_generator := is_gen_callable(call) or is_async_gen_callable(call)) and ( + return_args := get_args(return_annotation) ): return_annotation = return_args[0] - class_fields: Dict[str, Tuple[Any, Any]] = {} - dependencies: Dict[str, CallModel[..., Any]] = {} - custom_fields: Dict[str, CustomField] = {} - positional_args: List[str] = [] - keyword_args: List[str] = [] + class_fields: dict[str, tuple[Any, Any]] = {} + dependencies: dict[str, CallModel[..., Any]] = {} + custom_fields: dict[str, CustomField] = {} + positional_args: list[str] = [] + keyword_args: list[str] = [] var_positional_arg: Optional[str] = None var_keyword_arg: Optional[str] = None @@ -177,14 +170,19 @@ def build_call_model( class_fields[param_name] = (annotation, default) else: - class_fields[param_name] = class_fields.get(param_name, (Optional[annotation], None)) + class_fields[param_name] = class_fields.get( + param_name, (Optional[annotation], None) + ) keyword_args.append(param_name) else: if param.kind is param.KEYWORD_ONLY: keyword_args.append(param_name) - elif param.kind not in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD): + elif param.kind not in ( + inspect.Parameter.VAR_POSITIONAL, + inspect.Parameter.VAR_KEYWORD, + ): positional_args.append(param_name) func_model = create_model( # type: ignore[call-overload] @@ -193,9 +191,9 @@ def build_call_model( **class_fields, ) - response_model: Optional[Type[ResponseModel[T]]] = None + response_model: Optional[type[ResponseModel[T]]] = None if cast and return_annotation and return_annotation is not inspect.Parameter.empty: - response_model = create_model( # type: ignore[call-overload] + response_model = create_model( "ResponseModel", __config__=get_config_base(pydantic_config), response=(return_annotation, Ellipsis), diff --git a/fast_depends/core/model.py b/fast_depends/core/model.py index 0b5a120..12fe6b0 100644 --- a/fast_depends/core/model.py +++ b/fast_depends/core/model.py @@ -1,21 +1,14 @@ from collections import namedtuple +from collections.abc import Awaitable, Generator, Iterable, Sequence from contextlib import AsyncExitStack, ExitStack from functools import partial from inspect import Parameter, unwrap from itertools import chain from typing import ( Any, - Awaitable, Callable, - Dict, - Generator, Generic, - Iterable, - List, Optional, - Sequence, - Tuple, - Type, TypeVar, Union, ) @@ -55,18 +48,18 @@ class CallModel(Generic[P, T]): ] is_async: bool is_generator: bool - model: Optional[Type[BaseModel]] - response_model: Optional[Type[ResponseModel[T]]] + model: Optional[type[BaseModel]] + response_model: Optional[type[ResponseModel[T]]] - params: Dict[str, Tuple[Any, Any]] - alias_arguments: Tuple[str, ...] + params: dict[str, tuple[Any, Any]] + alias_arguments: tuple[str, ...] - dependencies: Dict[str, "CallModel[..., Any]"] + dependencies: dict[str, "CallModel[..., Any]"] extra_dependencies: Iterable["CallModel[..., Any]"] - sorted_dependencies: Tuple[Tuple["CallModel[..., Any]", int], ...] - custom_fields: Dict[str, CustomField] - keyword_args: Tuple[str, ...] - positional_args: Tuple[str, ...] + sorted_dependencies: tuple[tuple["CallModel[..., Any]", int], ...] + custom_fields: dict[str, CustomField] + keyword_args: tuple[str, ...] + positional_args: tuple[str, ...] var_positional_arg: Optional[str] var_keyword_arg: Optional[str] @@ -100,7 +93,7 @@ def call_name(self) -> str: return getattr(call, "__name__", type(call).__name__) @property - def flat_params(self) -> Dict[str, Tuple[Any, Any]]: + def flat_params(self) -> dict[str, tuple[Any, Any]]: params = self.params for d in (*self.dependencies.values(), *self.extra_dependencies): params.update(d.flat_params) @@ -109,18 +102,18 @@ def flat_params(self) -> Dict[str, Tuple[Any, Any]]: @property def flat_dependencies( self, - ) -> Dict[ + ) -> dict[ Callable[..., Any], - Tuple[ + tuple[ "CallModel[..., Any]", - Tuple[Callable[..., Any], ...], + tuple[Callable[..., Any], ...], ], ]: - flat: Dict[ + flat: dict[ Callable[..., Any], - Tuple[ + tuple[ CallModel[..., Any], - Tuple[Callable[..., Any], ...], + tuple[Callable[..., Any], ...], ], ] = {} @@ -145,20 +138,20 @@ def __init__( Callable[P, T], Callable[P, Awaitable[T]], ], - model: Optional[Type[BaseModel]], - params: Dict[str, Tuple[Any, Any]], - response_model: Optional[Type[ResponseModel[T]]] = None, + model: Optional[type[BaseModel]], + params: dict[str, tuple[Any, Any]], + response_model: Optional[type[ResponseModel[T]]] = None, use_cache: bool = True, cast: bool = True, is_async: bool = False, is_generator: bool = False, - dependencies: Optional[Dict[str, "CallModel[..., Any]"]] = None, + dependencies: Optional[dict[str, "CallModel[..., Any]"]] = None, extra_dependencies: Optional[Iterable["CallModel[..., Any]"]] = None, - keyword_args: Optional[List[str]] = None, - positional_args: Optional[List[str]] = None, + keyword_args: Optional[list[str]] = None, + positional_args: Optional[list[str]] = None, var_positional_arg: Optional[str] = None, var_keyword_arg: Optional[str] = None, - custom_fields: Optional[Dict[str, CustomField]] = None, + custom_fields: Optional[dict[str, CustomField]] = None, ): self.call = call self.model = model @@ -186,7 +179,7 @@ def __init__( self.extra_dependencies = extra_dependencies or () self.custom_fields = custom_fields or {} - sorted_dep: List[CallModel[..., Any]] = [] + sorted_dep: list[CallModel[..., Any]] = [] flat = self.flat_dependencies for calls in flat.values(): _sort_dep(sorted_dep, calls, flat) @@ -201,8 +194,8 @@ def __init__( def _solve( self, /, - *args: Tuple[Any, ...], - cache_dependencies: Dict[ + *args: tuple[Any, ...], + cache_dependencies: dict[ Union[ Callable[P, T], Callable[P, Awaitable[T]], @@ -210,7 +203,7 @@ def _solve( T, ], dependency_overrides: Optional[ - Dict[ + dict[ Union[ Callable[P, T], Callable[P, Awaitable[T]], @@ -221,11 +214,11 @@ def _solve( ], ] ] = None, - **kwargs: Dict[str, Any], + **kwargs: dict[str, Any], ) -> Generator[ - Tuple[ + tuple[ Sequence[Any], - Dict[str, Any], + dict[str, Any], Callable[..., Any], ], Any, @@ -243,7 +236,7 @@ def _solve( if self.use_cache and call in cache_dependencies: return cache_dependencies[call] - kw: Dict[str, Any] = {} + kw: dict[str, Any] = {} for arg in self.keyword_args: if (v := kwargs.pop(arg, Parameter.empty)) is not Parameter.empty: @@ -277,7 +270,7 @@ def _solve( if arg not in self.dependencies: kw[arg], args = args[0], args[1:] - solved_kw: Dict[str, Any] + solved_kw: dict[str, Any] solved_kw = yield args, kw, call args_: Sequence[Any] @@ -329,9 +322,9 @@ def _cast_response(self, /, value: Any) -> Any: def solve( self, /, - *args: Tuple[Any, ...], + *args: tuple[Any, ...], stack: ExitStack, - cache_dependencies: Dict[ + cache_dependencies: dict[ Union[ Callable[P, T], Callable[P, Awaitable[T]], @@ -339,7 +332,7 @@ def solve( T, ], dependency_overrides: Optional[ - Dict[ + dict[ Union[ Callable[P, T], Callable[P, Awaitable[T]], @@ -351,7 +344,7 @@ def solve( ] ] = None, nested: bool = False, - **kwargs: Dict[str, Any], + **kwargs: dict[str, Any], ) -> T: cast_gen = self._solve( *args, @@ -431,9 +424,9 @@ def solve( async def asolve( self, /, - *args: Tuple[Any, ...], + *args: tuple[Any, ...], stack: AsyncExitStack, - cache_dependencies: Dict[ + cache_dependencies: dict[ Union[ Callable[P, T], Callable[P, Awaitable[T]], @@ -441,7 +434,7 @@ async def asolve( T, ], dependency_overrides: Optional[ - Dict[ + dict[ Union[ Callable[P, T], Callable[P, Awaitable[T]], @@ -453,7 +446,7 @@ async def asolve( ] ] = None, nested: bool = False, - **kwargs: Dict[str, Any], + **kwargs: dict[str, Any], ) -> T: cast_gen = self._solve( *args, @@ -468,7 +461,7 @@ async def asolve( return cached_value # Heat cache and solve extra dependencies - dep_to_solve: List[Callable[..., Awaitable[Any]]] = [] + dep_to_solve: list[Callable[..., Awaitable[Any]]] = [] try: async with anyio.create_task_group() as tg: for dep, subdep in self.sorted_dependencies: @@ -512,7 +505,7 @@ async def asolve( **kwargs, ) - custom_to_solve: List[CustomField] = [] + custom_to_solve: list[CustomField] = [] try: async with anyio.create_task_group() as tg: @@ -556,16 +549,16 @@ async def asolve( def _sort_dep( - collector: List["CallModel[..., Any]"], - items: Tuple[ + collector: list["CallModel[..., Any]"], + items: tuple[ "CallModel[..., Any]", - Tuple[Callable[..., Any], ...], + tuple[Callable[..., Any], ...], ], - flat: Dict[ + flat: dict[ Callable[..., Any], - Tuple[ + tuple[ "CallModel[..., Any]", - Tuple[Callable[..., Any], ...], + tuple[Callable[..., Any], ...], ], ], ) -> None: diff --git a/fast_depends/dependencies/provider.py b/fast_depends/dependencies/provider.py index f3e2f0f..3f1f590 100644 --- a/fast_depends/dependencies/provider.py +++ b/fast_depends/dependencies/provider.py @@ -1,9 +1,10 @@ +from collections.abc import Iterator from contextlib import contextmanager -from typing import Any, Callable, Dict, Iterator +from typing import Any, Callable class Provider: - dependency_overrides: Dict[Callable[..., Any], Callable[..., Any]] + dependency_overrides: dict[Callable[..., Any], Callable[..., Any]] def __init__(self) -> None: self.dependency_overrides = {} diff --git a/fast_depends/library/model.py b/fast_depends/library/model.py index 8b18ea4..2bc046a 100644 --- a/fast_depends/library/model.py +++ b/fast_depends/library/model.py @@ -1,5 +1,5 @@ from abc import ABC -from typing import Any, Dict, Optional, TypeVar +from typing import Any, Optional, TypeVar Cls = TypeVar("Cls", bound="CustomField") @@ -31,9 +31,9 @@ def set_param_name(self: Cls, name: str) -> Cls: self.param_name = name return self - def use(self, /, **kwargs: Any) -> Dict[str, Any]: + def use(self, /, **kwargs: Any) -> dict[str, Any]: assert self.param_name, "You should specify `param_name` before using" return kwargs - def use_field(self, kwargs: Dict[str, Any]) -> None: + def use_field(self, kwargs: dict[str, Any]) -> None: raise NotImplementedError("You should implement `use_field` method.") diff --git a/fast_depends/schema.py b/fast_depends/schema.py index 2f065ef..b22e5d9 100644 --- a/fast_depends/schema.py +++ b/fast_depends/schema.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional +from typing import Any, Optional from fast_depends._compat import PYDANTIC_V2, create_model, model_schema from fast_depends.core import CallModel @@ -8,14 +8,13 @@ def get_schema( call: CallModel[Any, Any], embed: bool = False, resolve_refs: bool = False, -) -> Dict[str, Any]: +) -> dict[str, Any]: assert call.model, "Call should has a model" params_model = create_model( # type: ignore[call-overload] - call.model.__name__, - **call.flat_params + call.model.__name__, **call.flat_params ) - body: Dict[str, Any] = model_schema(params_model) + body: dict[str, Any] = model_schema(params_model) if not call.flat_params: body = {"title": body["title"], "type": "null"} @@ -32,11 +31,9 @@ def get_schema( def _move_pydantic_refs( - original: Any, - key: str, - refs: Optional[Dict[str, Any]] = None + original: Any, key: str, refs: Optional[dict[str, Any]] = None ) -> Any: - if not isinstance(original, Dict): + if not isinstance(original, dict): return original data = original.copy() @@ -53,7 +50,7 @@ def _move_pydantic_refs( elif isinstance(data[k], dict): data[k] = _move_pydantic_refs(data[k], key, refs) - elif isinstance(data[k], List): + elif isinstance(data[k], list): for i in range(len(data[k])): data[k][i] = _move_pydantic_refs(data[k][i], key, refs) diff --git a/fast_depends/use.py b/fast_depends/use.py index 0e88ede..0df6765 100644 --- a/fast_depends/use.py +++ b/fast_depends/use.py @@ -1,13 +1,11 @@ +from collections.abc import AsyncIterator, Iterator, Sequence from contextlib import AsyncExitStack, ExitStack from functools import partial, wraps from typing import ( Any, - AsyncIterator, Callable, - Iterator, Optional, Protocol, - Sequence, TypeVar, Union, cast, @@ -42,8 +40,7 @@ def __call__( self, func: Callable[P, T], model: Optional[CallModel[P, T]] = None, - ) -> Callable[P, T]: - ... + ) -> Callable[P, T]: ... @overload @@ -55,8 +52,7 @@ def inject( # pragma: no cover pydantic_config: Optional[ConfigDict] = None, dependency_overrides_provider: Optional[Any] = dependency_provider, wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x, -) -> _InjectWrapper[P, T]: - ... +) -> _InjectWrapper[P, T]: ... @overload @@ -68,8 +64,7 @@ def inject( # pragma: no cover pydantic_config: Optional[ConfigDict] = None, dependency_overrides_provider: Optional[Any] = dependency_provider, wrap_model: Callable[[CallModel[P, T]], CallModel[P, T]] = lambda x: x, -) -> Callable[P, T]: - ... +) -> Callable[P, T]: ... def inject( diff --git a/fast_depends/utils.py b/fast_depends/utils.py index d734125..c193808 100644 --- a/fast_depends/utils.py +++ b/fast_depends/utils.py @@ -1,19 +1,20 @@ import asyncio import functools import inspect -from contextlib import AsyncExitStack, ExitStack, asynccontextmanager, contextmanager +from collections.abc import AsyncGenerator, AsyncIterable, Awaitable +from contextlib import ( + AbstractContextManager, + AsyncExitStack, + ExitStack, + asynccontextmanager, + contextmanager, +) from typing import ( TYPE_CHECKING, + Annotated, Any, - AsyncGenerator, - AsyncIterable, - Awaitable, Callable, - ContextManager, - Dict, ForwardRef, - List, - Tuple, TypeVar, Union, cast, @@ -21,7 +22,6 @@ import anyio from typing_extensions import ( - Annotated, ParamSpec, get_args, get_origin, @@ -75,7 +75,7 @@ def solve_generator_sync( return stack.enter_context(cm) -def get_typed_signature(call: Callable[..., Any]) -> Tuple[inspect.Signature, Any]: +def get_typed_signature(call: Callable[..., Any]) -> tuple[inspect.Signature, Any]: signature = inspect.signature(call) locals = collect_outer_stack_locals() @@ -105,10 +105,10 @@ def get_typed_signature(call: Callable[..., Any]) -> Tuple[inspect.Signature, An ) -def collect_outer_stack_locals() -> Dict[str, Any]: +def collect_outer_stack_locals() -> dict[str, Any]: frame = inspect.currentframe() - frames: List[FrameType] = [] + frames: list[FrameType] = [] while frame is not None: if "fast_depends" not in frame.f_code.co_filename: frames.append(frame) @@ -123,8 +123,8 @@ def collect_outer_stack_locals() -> Dict[str, Any]: def get_typed_annotation( annotation: Any, - globalns: Dict[str, Any], - locals: Dict[str, Any], + globalns: dict[str, Any], + locals: dict[str, Any], ) -> Any: if isinstance(annotation, str): annotation = ForwardRef(annotation) @@ -134,8 +134,9 @@ def get_typed_annotation( if get_origin(annotation) is Annotated and (args := get_args(annotation)): solved_args = [get_typed_annotation(x, globalns, locals) for x in args] - annotation.__origin__, annotation.__metadata__ = solved_args[0], tuple( - solved_args[1:] + annotation.__origin__, annotation.__metadata__ = ( + solved_args[0], + tuple(solved_args[1:]), ) return annotation @@ -143,7 +144,7 @@ def get_typed_annotation( @asynccontextmanager async def contextmanager_in_threadpool( - cm: ContextManager[T], + cm: AbstractContextManager[T], ) -> AsyncGenerator[T, None]: exit_limiter = anyio.CapacityLimiter(1) try: diff --git a/pyproject.toml b/pyproject.toml index 84629ef..f5138f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ authors = [ keywords = ["fastapi", "dependency injection"] -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Development Status :: 5 - Production/Stable", @@ -21,11 +21,11 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Libraries", @@ -43,7 +43,6 @@ dynamic = ["version"] dependencies = [ "pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0", "anyio>=3.0.0,<5.0.0", - "typing-extensions<4.12.1; python_version < '3.9'", ] [project.urls] @@ -74,6 +73,9 @@ ignore_missing_imports = true profile = "black" known_third_party = ["pydantic", "anyio"] +[tool.ruff] +target-version = "py39" + [tool.ruff.lint] select = [ "E", # pycodestyle errors https://docs.astral.sh/ruff/rules/#error-e diff --git a/scripts/lint.sh b/scripts/lint.sh index 46ef1eb..9f9b300 100644 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -5,7 +5,7 @@ echo "Running ruff linter (isort, flake, pyupgrade, etc. replacement)..." ruff check fast_depends tests --fix echo "Running ruff formatter (black replacement)..." -ruff format tests +ruff format fast_depends tests echo "Running codespell to find typos..." codespell diff --git a/tests/async/test_cast.py b/tests/async/test_cast.py index f6ac5ae..c660089 100644 --- a/tests/async/test_cast.py +++ b/tests/async/test_cast.py @@ -1,9 +1,9 @@ -from typing import Dict, Iterator, Tuple +from collections.abc import Iterator +from typing import Annotated import pytest from annotated_types import Ge from pydantic import BaseModel, Field, ValidationError -from typing_extensions import Annotated from fast_depends import inject from tests.marks import pydanticV2 @@ -141,9 +141,9 @@ async def test_args_kwargs_1(): @inject async def simple_func( a: int, - *args: Tuple[float, ...], + *args: tuple[float, ...], b: int, - **kwargs: Dict[str, int], + **kwargs: dict[str, int], ): return a, args, b, kwargs @@ -157,7 +157,7 @@ async def test_args_kwargs_2(): @inject async def simple_func( a: int, - *args: Tuple[float, ...], + *args: tuple[float, ...], b: int, ): return a, args, b diff --git a/tests/async/test_depends.py b/tests/async/test_depends.py index ee12e9e..61447c4 100644 --- a/tests/async/test_depends.py +++ b/tests/async/test_depends.py @@ -2,11 +2,11 @@ from contextlib import asynccontextmanager from dataclasses import dataclass from functools import partial +from typing import Annotated from unittest.mock import Mock import pytest from pydantic import ValidationError -from typing_extensions import Annotated from fast_depends import Depends, inject diff --git a/tests/library/test_custom.py b/tests/library/test_custom.py index a2b0b13..be787f8 100644 --- a/tests/library/test_custom.py +++ b/tests/library/test_custom.py @@ -1,12 +1,11 @@ import logging from time import monotonic_ns -from typing import Any, Dict +from typing import Annotated, Any import anyio import pydantic import pytest from annotated_types import Ge -from typing_extensions import Annotated from fast_depends import Depends, inject from fast_depends.library import CustomField @@ -14,7 +13,7 @@ class Header(CustomField): - def use(self, /, **kwargs: Any) -> Dict[str, Any]: + def use(self, /, **kwargs: Any) -> dict[str, Any]: kwargs = super().use(**kwargs) if v := kwargs.get("headers", {}).get(self.param_name): kwargs[self.param_name] = v @@ -32,7 +31,7 @@ def use_field(self, kwargs: Any) -> None: class AsyncHeader(Header): - async def use(self, /, **kwargs: Any) -> Dict[str, Any]: + async def use(self, /, **kwargs: Any) -> dict[str, Any]: return super().use(**kwargs) diff --git a/tests/sync/test_cast.py b/tests/sync/test_cast.py index b50b133..7d1eed1 100644 --- a/tests/sync/test_cast.py +++ b/tests/sync/test_cast.py @@ -1,9 +1,9 @@ -from typing import Dict, Iterator, Tuple +from collections.abc import Iterator +from typing import Annotated import pytest from annotated_types import Ge from pydantic import BaseModel, Field, ValidationError -from typing_extensions import Annotated from fast_depends import inject from tests.marks import pydanticV2 @@ -141,9 +141,9 @@ def test_args_kwargs_1(): @inject def simple_func( a: int, - *args: Tuple[float, ...], + *args: tuple[float, ...], b: int, - **kwargs: Dict[str, int], + **kwargs: dict[str, int], ): return a, args, b, kwargs @@ -154,7 +154,7 @@ def test_args_kwargs_2(): @inject def simple_func( a: int, - *args: Tuple[float, ...], + *args: tuple[float, ...], b: int, ): return a, args, b diff --git a/tests/sync/test_depends.py b/tests/sync/test_depends.py index c1a2fe2..8dd8e4f 100644 --- a/tests/sync/test_depends.py +++ b/tests/sync/test_depends.py @@ -2,11 +2,11 @@ from contextlib import contextmanager from dataclasses import dataclass from functools import partial +from typing import Annotated from unittest.mock import Mock import pytest from pydantic import ValidationError -from typing_extensions import Annotated from fast_depends import Depends, inject