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

feat: make pydantic optional #77

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d4ca672
feat: make pydantic optional
Lancetnik Mar 1, 2024
1b4aa15
fix: pydantic V1 compatibility
Lancetnik Mar 1, 2024
cd33029
chore: make pydantic optional
Lancetnik Mar 1, 2024
df8c62c
chore: update CI
Lancetnik Mar 1, 2024
71319c3
fix: pydantic V2 compatibility
Lancetnik Mar 1, 2024
c399226
fix: correct coverage file name
Lancetnik Mar 1, 2024
5e9fb6e
chore: rm useless coverage
Lancetnik Mar 1, 2024
01f4bb8
refactor: use pydantic TypeAdapter in V2
Lancetnik Mar 4, 2024
1c647e2
refactor: use if TYPE_CHECKING in use.py
Lancetnik Mar 4, 2024
1417d35
refactor: new provider logic
Lancetnik Mar 6, 2024
0107125
chore: new pip cache key for no-pydantic CI
Lancetnik Mar 6, 2024
51c1de4
chore: ignore missing
Lancetnik Mar 6, 2024
b1d77b5
feat: add msgspec serializer
Lancetnik Aug 30, 2024
88ba386
chore: update stuff
Lancetnik Aug 30, 2024
4920b50
chore: #97 pr
Lancetnik Aug 30, 2024
4030f98
chore: #100 pr
Lancetnik Sep 5, 2024
21c2f61
chore: #111 pr
Lancetnik Sep 5, 2024
0c1ec53
chore: #112 pr
Lancetnik Sep 5, 2024
f56d11b
chore: #115 pr
Lancetnik Sep 5, 2024
d4ffecb
chore: #120 pr
Lancetnik Sep 5, 2024
187616b
chore: #124 pr
Lancetnik Sep 5, 2024
78ccd68
chore: #125 pr
Lancetnik Sep 5, 2024
edfb458
chore: #127 pr
Lancetnik Sep 5, 2024
d189448
chore: set alpha release
Lancetnik Sep 5, 2024
364421e
chore: 3.0.0a1 release
Lancetnik Oct 29, 2024
cebcf28
chore: python3.9 compat
Lancetnik Oct 31, 2024
5d7e716
chore: run tests for PR
Lancetnik Oct 31, 2024
5152426
chore: fix dependencies
Lancetnik Nov 5, 2024
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
10 changes: 9 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ updates:
directory: "/"
schedule:
interval: "weekly"
groups:
github-actions:
patterns:
- "*"
# Python
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
interval: "weekly"
groups:
pip:
patterns:
- "*"
41 changes: 36 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Test

on:
push:
branches:
- main
schedule:
- cron: "0 0 * * *"
pull_request:
types: [opened, synchronize]
types:
- opened
- synchronize
- ready_for_review

jobs:
test:
Expand Down Expand Up @@ -49,8 +51,37 @@ jobs:
path: coverage
if-no-files-found: error

test-no-pydantic:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: no-pydantic-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements.test.txt
- run: mkdir coverage
- name: Test
run: bash scripts/test.sh
env:
COVERAGE_FILE: coverage/.coverage.no-pydantic
CONTEXT: no-pydantic
- name: Store coverage files
uses: actions/upload-artifact@v4
with:
name: .coverage.no-pydantic
path: coverage
if-no-files-found: error

coverage-combine:
needs: [test]
needs: [test,test-no-pydantic]
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

---

Documentation: https://lancetnik.github.io/FastDepends/
Documentation: <https://lancetnik.github.io/FastDepends/>

---

Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/advanced/custom/cast_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def __init__(self):
def func(
h1: int = Header(), # <-- casts to int
h2: int = NotCastHeader() # <-- just an annotation
): ...
): ...
1 change: 1 addition & 0 deletions docs/docs_src/advanced/custom/class_declaration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fast_depends.library import CustomField


class Header(CustomField):
def use(self, /, **kwargs):
kwargs = super().use(**kwargs)
Expand Down
7 changes: 4 additions & 3 deletions docs/docs_src/advanced/custom/starlette.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from fast_depends import inject
from fast_depends.library import CustomField

from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
from starlette.routing import Route

from fast_depends import inject
from fast_depends.library import CustomField


class Path(CustomField):
def use(self, /, *, request, **kwargs):
return {
Expand Down
3 changes: 2 additions & 1 deletion docs/docs_src/advanced/custom/usage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from fast_depends import inject


@inject
def my_func(header_field: int = Header()):
return header_field

assert h(
headers={"header_field": "1"}
) == 1
) == 1
5 changes: 3 additions & 2 deletions docs/docs_src/home/1_async_tutor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

from fast_depends import inject, Depends
from fast_depends import Depends, inject


async def dependency(a: int) -> int:
return a
Expand All @@ -13,4 +14,4 @@ async def main(
) -> float:
return a + b + c

assert asyncio.run(main("1", 2)) == 4.0
assert asyncio.run(main("1", 2)) == 4.0
5 changes: 3 additions & 2 deletions docs/docs_src/home/1_sync_tutor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import inject, Depends
from fast_depends import Depends, inject


def dependency(a: int) -> int:
return a
Expand All @@ -11,4 +12,4 @@ def main(
) -> float:
return a + b + c

assert main("1", 2) == 4.0
assert main("1", 2) == 4.0
4 changes: 3 additions & 1 deletion docs/docs_src/how-it-works/works.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pydantic import BaseModel

from fast_depends import Depends


def simple_dependency(a: int, **kwargs):
return a

Expand Down Expand Up @@ -28,4 +30,4 @@ class ResponseModel(BaseModel):
field: float

# Cast response
real_response = ResponseModel(field=base_response).field
real_response = ResponseModel(field=base_response).field
6 changes: 4 additions & 2 deletions docs/docs_src/tutorial_1_quickstart/1_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
from fast_depends import inject, Depends

from fast_depends import Depends, inject


async def simple_dependency(a: int, b: int = 3):
return a + b
Expand All @@ -15,4 +17,4 @@ async def method(
):
return a + b + c

assert asyncio.run(method("1")) == 6
assert asyncio.run(method("1")) == 6
5 changes: 3 additions & 2 deletions docs/docs_src/tutorial_1_quickstart/1_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import inject, Depends
from fast_depends import Depends, inject


def simple_dependency(a: int, b: int = 3):
return a + b
Expand All @@ -7,4 +8,4 @@ def simple_dependency(a: int, b: int = 3):
def method(a: int, d: int = Depends(simple_dependency)):
return a + d

assert method("1") == 5
assert method("1") == 5
6 changes: 4 additions & 2 deletions docs/docs_src/tutorial_1_quickstart/2_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
from fast_depends import inject, Depends

from fast_depends import Depends, inject


def another_dependency(a: int):
return a * 2
Expand All @@ -15,4 +17,4 @@ async def method(
):
return a + b + c

assert asyncio.run(method("1")) == 6
assert asyncio.run(method("1")) == 6
5 changes: 3 additions & 2 deletions docs/docs_src/tutorial_1_quickstart/2_sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import inject, Depends
from fast_depends import Depends, inject


def another_dependency(a: int):
return a * 2
Expand All @@ -14,4 +15,4 @@ def method(
):
return a + b + c

assert method("1") == 6
assert method("1") == 6
2 changes: 1 addition & 1 deletion docs/docs_src/tutorial_2_classes/tutorial_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def f(): pass
class MyClass
def f(self): pass

MyClass().f() # "call"? 4-th call
MyClass().f() # "call"? 4-th call
6 changes: 4 additions & 2 deletions docs/docs_src/tutorial_2_classes/tutorial_2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any
from fast_depends import inject, Depends

from fast_depends import Depends, inject


class MyDependency:
def __init__(self, a: int):
Expand All @@ -9,4 +11,4 @@ def __init__(self, a: int):
def func(d: Any = Depends(MyDependency)):
return d.field

assert func(a=3) == 3
assert func(a=3) == 3
5 changes: 3 additions & 2 deletions docs/docs_src/tutorial_2_classes/tutorial_3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import inject, Depends
from fast_depends import Depends, inject


class MyDependency:
def __init__(self, a: int):
Expand All @@ -11,4 +12,4 @@ def __call__(self, b: int):
def func(d: int = Depends(MyDependency(3))):
return d

assert func(b=3) == 6
assert func(b=3) == 6
5 changes: 3 additions & 2 deletions docs/docs_src/tutorial_2_classes/tutorial_4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import inject, Depends
from fast_depends import Depends, inject


class MyDependency:
@staticmethod
Expand All @@ -9,4 +10,4 @@ def dep(a: int):
def func(d: int = Depends(MyDependency.dep)):
return d

assert func(a=3) == 9
assert func(a=3) == 9
5 changes: 3 additions & 2 deletions docs/docs_src/tutorial_2_classes/tutorial_5.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import inject, Depends
from fast_depends import Depends, inject


class MyDependency:
def __init__(self, a):
Expand All @@ -11,4 +12,4 @@ def dep(self, a: int):
def func(d: int = Depends(MyDependency(3).dep)):
return d

assert func(a=3) == 6
assert func(a=3) == 6
9 changes: 6 additions & 3 deletions docs/docs_src/tutorial_4_annotated/annotated_36.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing_extensions import Annotated
from fast_depends import Depends, inject
from typing import Annotated

from pydantic import BaseModel, PositiveInt

from fast_depends import Depends, inject


class User(BaseModel):
user_id: PositiveInt

Expand All @@ -16,4 +19,4 @@ def do_smth_with_user(user: CurrentUser):

@inject
def do_another_smth_with_user(user: CurrentUser):
...
...
7 changes: 5 additions & 2 deletions docs/docs_src/tutorial_4_annotated/annotated_39.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import Annotated
from fast_depends import Depends, inject

from pydantic import BaseModel, PositiveInt

from fast_depends import Depends, inject


class User(BaseModel):
user_id: PositiveInt

Expand All @@ -16,4 +19,4 @@ def do_smth_with_user(user: CurrentUser):

@inject
def do_another_smth_with_user(user: CurrentUser):
...
...
8 changes: 5 additions & 3 deletions docs/docs_src/tutorial_4_annotated/annotated_variants_36.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing_extensions import Annotated
from fast_depends import Depends
from typing import Annotated

from pydantic import Field

from fast_depends import Depends

CurrentUser = Annotated[User, Depends(get_user)]
MaxLenField = Annotated[str, Field(..., max_length="32")]
MaxLenField = Annotated[str, Field(..., max_length="32")]
6 changes: 4 additions & 2 deletions docs/docs_src/tutorial_4_annotated/annotated_variants_39.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Annotated
from fast_depends import Depends

from pydantic import Field

from fast_depends import Depends

CurrentUser = Annotated[User, Depends(get_user)]
MaxLenField = Annotated[str, Field(..., max_length="32")]
MaxLenField = Annotated[str, Field(..., max_length="32")]
6 changes: 4 additions & 2 deletions docs/docs_src/tutorial_4_annotated/not_annotated.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from fast_depends import Depends, inject
from pydantic import BaseModel, PositiveInt

from fast_depends import Depends, inject


class User(BaseModel):
user_id: PositiveInt

Expand All @@ -13,4 +15,4 @@ def do_smth_with_user(user: User = Depends(get_user)):

@inject
def do_another_smth_with_user(user: User = Depends(get_user)):
...
...
3 changes: 2 additions & 1 deletion docs/docs_src/tutorial_5_overrides/example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fast_depends import Depends, inject, dependency_provider
from fast_depends import Depends, dependency_provider, inject


def original_dependency():
raise NotImplementedError()
Expand Down
3 changes: 2 additions & 1 deletion docs/docs_src/tutorial_5_overrides/fixture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from fast_depends import dependency_provider, inject, Depends

from fast_depends import Depends, dependency_provider, inject

# Base code

Expand Down
Loading