Skip to content

Commit

Permalink
tests: pydanticV1 skip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Aug 11, 2024
1 parent 9d85172 commit 5e20849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 8 additions & 9 deletions fast_depends/core/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,22 @@ def build_call_model(
default = ()
elif param_name == "kwargs":
default = {}
elif param.default is inspect.Parameter.empty:
default = Ellipsis
else:
default = param.default

if isinstance(default, Depends):
assert (
not dep
), "You can not use `Depends` with `Annotated` and default both"
dep, default = default, ...
dep, default = default, Ellipsis

elif isinstance(default, CustomField):
assert (
not custom
), "You can not use `CustomField` with `Annotated` and default both"
custom, default = default, ...

elif default is inspect.Parameter.empty:
class_fields[param_name] = (annotation, ...)
custom, default = default, Ellipsis

else:
class_fields[param_name] = (annotation, default)
Expand All @@ -155,7 +154,7 @@ def build_call_model(
)

if dep.cast is True:
class_fields[param_name] = (annotation, ...)
class_fields[param_name] = (annotation, Ellipsis)

keyword_args.append(param_name)

Expand Down Expand Up @@ -192,10 +191,10 @@ def build_call_model(

response_model: Optional[Type[ResponseModel[T]]] = None
if cast and return_annotation and return_annotation is not inspect.Parameter.empty:
response_model = create_model(
response_model = create_model( # type: ignore[call-overload]
"ResponseModel",
__config__=get_config_base(pydantic_config), # type: ignore[assignment]
response=(return_annotation, ...),
__config__=get_config_base(pydantic_config),
response=(return_annotation, Ellipsis),
)

return CallModel(
Expand Down
4 changes: 3 additions & 1 deletion tests/library/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from fast_depends import Depends, inject
from fast_depends.library import CustomField
from tests.marks import pydanticV2


class Header(CustomField):
Expand Down Expand Up @@ -129,13 +130,14 @@ def sync_catch(key: Annotated[int, Header()]):
assert sync_catch(headers={"key": "1"}) == 1


@pydanticV2
def test_annotated_header_with_meta():
@inject
def sync_catch(key: Annotated[int, Header(), Ge(3)] = 3): # noqa: B008
return key

with pytest.raises(pydantic.ValidationError):
assert sync_catch(headers={"key": "2"})
sync_catch(headers={"key": "2"})

assert sync_catch(headers={"key": "4"}) == 4

Expand Down

0 comments on commit 5e20849

Please sign in to comment.