@@ -5,24 +5,11 @@ from collections.abc import Awaitable
55from inspect import CO_ITERABLE_COROUTINE
66from types import CoroutineType, GeneratorType
77
8- from .providers cimport Provider, Resource, NULL_AWAITABLE
8+ from .providers cimport Provider, Resource
99from .wiring import _Marker
1010
11- cimport cython
1211
13- 14- @cython.internal
15- @cython.no_gc
16- cdef class KWPair:
17- cdef str name
18- cdef object value
19- 20- def __cinit__ (self , str name , object value , /):
21- self .name = name
22- self .value = value
23- 24- 25- cdef inline bint _is_injectable(dict kwargs, str name):
12+ cdef inline bint _is_injectable(dict kwargs, object name):
2613 return name not in kwargs or isinstance (kwargs[name], _Marker)
2714
2815
@@ -38,11 +25,8 @@ cdef class DependencyResolver:
3825 self .injections = injections
3926 self .closings = closings
4027
41- async def _await_injection(self , kw_pair: KWPair, / ) - > None :
42- self .to_inject[kw_pair.name] = await kw_pair.value
43- 44- cdef object _await_injections(self , to_await: list ):
45- return gather(* map (self ._await_injection, to_await))
28+ async def _await_injection(self , name: str , value: object , / ) - > None :
29+ self .to_inject[name] = await value
4630
4731 cdef void _handle_injections_sync(self ):
4832 cdef Provider provider
@@ -60,7 +44,7 @@ cdef class DependencyResolver:
6044 provide = provider()
6145
6246 if provider.is_async_mode_enabled() or _isawaitable(provide):
63- to_await.append(KWPair (name, provide))
47+ to_await.append(self ._await_injection (name, provide))
6448 else :
6549 self .to_inject[name] = provide
6650
@@ -93,13 +77,12 @@ cdef class DependencyResolver:
9377
9478 async def __aenter__(self ):
9579 if to_await := self ._handle_injections_async():
96- await self ._await_injections( to_await)
80+ await gather( * to_await)
9781 return self .to_inject
9882
99- def __aexit__ (self , *_ ):
83+ async def __aexit__(self , * _):
10084 if to_await := self ._handle_closings_async():
101- return gather(* to_await)
102- return NULL_AWAITABLE
85+ await gather(* to_await)
10386
10487
10588cdef bint _isawaitable(object instance):
0 commit comments