Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump python versions #139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions fast_depends/_compat.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -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]
Expand Down
38 changes: 18 additions & 20 deletions fast_depends/core/build.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand All @@ -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),
Expand Down
Loading