File tree Expand file tree Collapse file tree 4 files changed +26
-25
lines changed
samples/wiringfastdepends Expand file tree Collapse file tree 4 files changed +26
-25
lines changed Original file line number Diff line number Diff line change @@ -48,5 +48,3 @@ Just use it within ``Depends``
48
48
container.wire(modules = [sys.modules[__name__ ]])
49
49
50
50
apply_coefficient(100 ) == 120.0
51
-
52
-
Original file line number Diff line number Diff line change @@ -47,46 +47,48 @@ def get_args(hint):
47
47
def get_origin (tp ):
48
48
return None
49
49
50
+
50
51
MARKER_EXTRACTORS = []
51
52
52
53
try :
53
- from fastapi .params import Depends as FastApiDepends
54
+ from fastapi .params import Depends as FastAPIDepends
54
55
except ImportError :
55
56
pass
56
57
else :
58
+
57
59
def extract_marker_from_fastapi (param : Any ) -> Any :
58
- if isinstance (param , FastApiDepends ):
60
+ if isinstance (param , FastAPIDepends ):
59
61
return param .dependency
60
62
return None
61
63
62
64
MARKER_EXTRACTORS .append (extract_marker_from_fastapi )
63
65
64
-
65
- try :
66
- import starlette .requests
67
- except ImportError :
68
- starlette = None
69
-
70
-
71
- try :
72
- import werkzeug .local
73
- except ImportError :
74
- werkzeug = None
75
-
76
-
77
66
try :
78
67
from fast_depends .dependencies import Depends as FastDepends
79
68
except ImportError :
80
69
pass
81
70
else :
71
+
82
72
def extract_marker_from_fast_depends (param : Any ) -> Any :
83
73
if isinstance (param , FastDepends ):
84
74
return param .dependency
85
75
return None
86
76
87
77
MARKER_EXTRACTORS .append (extract_marker_from_fast_depends )
88
78
89
- from . import providers
79
+
80
+ try :
81
+ import starlette .requests
82
+ except ImportError :
83
+ starlette = None
84
+
85
+
86
+ try :
87
+ import werkzeug .local
88
+ except ImportError :
89
+ werkzeug = None
90
+
91
+ from . import providers # noqa: E402
90
92
91
93
__all__ = (
92
94
"wire" ,
Original file line number Diff line number Diff line change 1
1
import sys
2
2
3
- from dependency_injector import containers , providers
4
- from dependency_injector .wiring import inject , Provide
5
3
from fast_depends import Depends
6
4
from typing_extensions import Annotated
7
5
6
+ from dependency_injector import containers , providers
7
+ from dependency_injector .wiring import Provide , inject
8
+
8
9
9
10
class CoefficientService :
10
11
@staticmethod
@@ -27,10 +28,12 @@ def apply_coefficient(
27
28
@inject
28
29
def apply_coefficient_annotated (
29
30
a : int ,
30
- coefficient_provider : Annotated [CoefficientService , Depends (Provide [Container .service ])],
31
+ coefficient_provider : Annotated [
32
+ CoefficientService , Depends (Provide [Container .service ])
33
+ ],
31
34
) -> float :
32
35
return a * coefficient_provider .get_coefficient ()
33
36
34
37
35
38
container = Container ()
36
- container .wire (modules = [sys .modules [__name__ ]])
39
+ container .wire (modules = [sys .modules [__name__ ]])
Original file line number Diff line number Diff line change 1
- from dependency_injector .wiring import inject , Provide
2
-
3
1
from wiringfastdepends import sample
4
2
5
3
@@ -8,4 +6,4 @@ def test_apply_coefficient() -> None:
8
6
9
7
10
8
def test_apply_coefficient_annotated () -> None :
11
- assert sample .apply_coefficient_annotated (100 ) == 120.0
9
+ assert sample .apply_coefficient_annotated (100 ) == 120.0
You can’t perform that action at this time.
0 commit comments