Skip to content

Commit e2cf0d0

Browse files
Fast depends v3 compatibility fix
1 parent 5a1aef9 commit e2cf0d0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/dependency_injector/wiring.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,29 @@ def extract_marker_from_fastapi(param: Any) -> Any:
7676

7777
MARKER_EXTRACTORS.append(extract_marker_from_fastapi)
7878

79+
# Fast-depends support for both old and new versions
80+
FastDepends = None
81+
FastDependant = None
82+
83+
# Try to import from different locations to support both versions
84+
with suppress(ImportError):
85+
# Try version 3.0.0+ first (Dependant from model)
86+
from fast_depends.dependencies.model import Dependant as FastDependant
87+
88+
def extract_marker_from_dependant_fast_depends(param: Any) -> Any:
89+
# Check for Dependant (3.0.0+)
90+
if FastDependant is not None and isinstance(param, FastDependant):
91+
return param.dependency
92+
return None
93+
94+
MARKER_EXTRACTORS.append(extract_marker_from_dependant_fast_depends)
95+
7996
with suppress(ImportError):
97+
# Try version < 3.0.0 (Depends class)
8098
from fast_depends.dependencies import Depends as FastDepends
8199

82100
def extract_marker_from_fast_depends(param: Any) -> Any:
83-
if isinstance(param, FastDepends):
101+
if FastDepends is not None and isinstance(param, FastDepends):
84102
return param.dependency
85103
return None
86104

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ deps=
1717
mypy_boto3_s3
1818
pydantic-settings
1919
werkzeug
20-
fast-depends
20+
fast-depends==3.0.0
2121
extras=
2222
yaml
2323
commands = pytest
@@ -45,7 +45,7 @@ deps =
4545
boto3
4646
mypy_boto3_s3
4747
werkzeug
48-
fast-depends
48+
fast-depends==3.0.0
4949
commands = pytest -m pydantic
5050

5151
[testenv:coveralls]

0 commit comments

Comments
 (0)