11from abc import abstractmethod
2- from collections .abc import Callable
2+ from collections .abc import Awaitable , Callable
33from contextlib import ContextDecorator
44from enum import Enum
55from logging import Logger
@@ -21,6 +21,9 @@ from ._core.module import ModeStr, PriorityStr
2121
2222_ : Module = ...
2323
24+ afind_instance = _ .afind_instance
25+ aget_instance = _ .aget_instance
26+ aget_lazy_instance = _ .aget_lazy_instance
2427constant = _ .constant
2528find_instance = _ .find_instance
2629get_instance = _ .get_instance
@@ -53,59 +56,59 @@ class Module:
5356 def __contains__ (self , cls : _InputType [Any ], / ) -> bool : ...
5457 @property
5558 def is_locked (self ) -> bool : ...
56- def inject [** P , T ](self , wrapped : Callable [P , T ] = ..., / ): # type: ignore[no-untyped-def]
59+ def inject [** P , T ](self , wrapped : Callable [P , T ] = ..., / ) -> Any :
5760 """
5861 Decorator applicable to a class or function. Inject function dependencies using
5962 parameter type annotations. If applied to a class, the dependencies resolved
6063 will be those of the `__init__` method.
6164 """
6265
63- def injectable [** P , T ]( # type: ignore[no-untyped-def]
66+ def injectable [** P , T ](
6467 self ,
65- wrapped : Callable [P , T ] = ...,
68+ wrapped : Callable [P , T ] | Callable [ P , Awaitable [ T ]] = ...,
6669 / ,
6770 * ,
6871 cls : _InjectableFactory [T ] = ...,
6972 inject : bool = ...,
7073 on : _TypeInfo [T ] = ...,
7174 mode : Mode | ModeStr = ...,
72- ):
75+ ) -> Any :
7376 """
7477 Decorator applicable to a class or function. It is used to indicate how the
7578 injectable will be constructed. At injection time, a new instance will be
7679 injected each time.
7780 """
7881
79- def singleton [** P , T ]( # type: ignore[no-untyped-def]
82+ def singleton [** P , T ](
8083 self ,
81- wrapped : Callable [P , T ] = ...,
84+ wrapped : Callable [P , T ] | Callable [ P , Awaitable [ T ]] = ...,
8285 / ,
8386 * ,
8487 inject : bool = ...,
8588 on : _TypeInfo [T ] = ...,
8689 mode : Mode | ModeStr = ...,
87- ):
90+ ) -> Any :
8891 """
8992 Decorator applicable to a class or function. It is used to indicate how the
9093 singleton will be constructed. At injection time, the injected instance will
9194 always be the same.
9295 """
9396
94- def should_be_injectable [T ](self , wrapped : type [T ] = ..., / ): # type: ignore[no-untyped-def]
97+ def should_be_injectable [T ](self , wrapped : type [T ] = ..., / ) -> Any :
9598 """
9699 Decorator applicable to a class. It is used to specify whether an injectable
97100 should be registered. Raise an exception at injection time if the class isn't
98101 registered.
99102 """
100103
101- def constant [T ]( # type: ignore[no-untyped-def]
104+ def constant [T ](
102105 self ,
103106 wrapped : type [T ] = ...,
104107 / ,
105108 * ,
106109 on : _TypeInfo [T ] = ...,
107110 mode : Mode | ModeStr = ...,
108- ):
111+ ) -> Any :
109112 """
110113 Decorator applicable to a class or function. It is used to indicate how the
111114 constant is constructed. At injection time, the injected instance will always
@@ -131,12 +134,25 @@ class Module:
131134 wrapped : Callable [P , T ],
132135 / ,
133136 ) -> Callable [P , T ]: ...
137+ async def afind_instance [T ](self , cls : _InputType [T ]) -> T : ...
134138 def find_instance [T ](self , cls : _InputType [T ]) -> T :
135139 """
136140 Function used to retrieve an instance associated with the type passed in
137141 parameter or an exception will be raised.
138142 """
139143
144+ @overload
145+ async def aget_instance [T , Default ](
146+ self ,
147+ cls : _InputType [T ],
148+ default : Default ,
149+ ) -> T | Default : ...
150+ @overload
151+ async def aget_instance [T ](
152+ self ,
153+ cls : _InputType [T ],
154+ default : None = ...,
155+ ) -> T | None : ...
140156 @overload
141157 def get_instance [T , Default ](
142158 self ,
@@ -149,12 +165,28 @@ class Module:
149165 """
150166
151167 @overload
152- def get_instance [T , _ ](
168+ def get_instance [T ](
153169 self ,
154170 cls : _InputType [T ],
155171 default : None = ...,
156172 ) -> T | None : ...
157173 @overload
174+ def aget_lazy_instance [T , Default ](
175+ self ,
176+ cls : _InputType [T ],
177+ default : Default ,
178+ * ,
179+ cache : bool = ...,
180+ ) -> Awaitable [T | Default ]: ...
181+ @overload
182+ def aget_lazy_instance [T ](
183+ self ,
184+ cls : _InputType [T ],
185+ default : None = ...,
186+ * ,
187+ cache : bool = ...,
188+ ) -> Awaitable [T | None ]: ...
189+ @overload
158190 def get_lazy_instance [T , Default ](
159191 self ,
160192 cls : _InputType [T ],
@@ -172,7 +204,7 @@ class Module:
172204 """
173205
174206 @overload
175- def get_lazy_instance [T , _ ](
207+ def get_lazy_instance [T ](
176208 self ,
177209 cls : _InputType [T ],
178210 default : None = ...,
@@ -229,6 +261,7 @@ class Module:
229261 Function to unlock the module by deleting cached instances of singletons.
230262 """
231263
264+ async def all_ready (self ) -> None : ...
232265 def add_logger (self , logger : Logger ) -> Self : ...
233266 @classmethod
234267 def from_name (cls , name : str ) -> Module :
@@ -253,6 +286,8 @@ class Injectable[T](Protocol):
253286 def is_locked (self ) -> bool : ...
254287 def unlock (self ) -> None : ...
255288 @abstractmethod
289+ async def aget_instance (self ) -> T : ...
290+ @abstractmethod
256291 def get_instance (self ) -> T : ...
257292
258293@final
0 commit comments