mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
move back decorator into .py file to carry signature
This commit is contained in:
parent
cc2304e46e
commit
4af4685918
File diff suppressed because it is too large
Load Diff
|
@ -12,23 +12,21 @@ from .wiring import _Marker, PatchedCallable
|
|||
from .providers cimport Provider
|
||||
|
||||
|
||||
def _get_sync_patched(fn, patched: PatchedCallable):
|
||||
@functools.wraps(fn)
|
||||
def _patched(*args, **kwargs):
|
||||
def _sync_inject(object fn, tuple args, dict kwargs, dict injections, dict closings):
|
||||
cdef object result
|
||||
cdef dict to_inject
|
||||
cdef object arg_key
|
||||
cdef Provider provider
|
||||
|
||||
to_inject = kwargs.copy()
|
||||
for arg_key, provider in patched.injections.items():
|
||||
for arg_key, provider in injections.items():
|
||||
if arg_key not in kwargs or isinstance(kwargs[arg_key], _Marker):
|
||||
to_inject[arg_key] = provider()
|
||||
|
||||
result = fn(*args, **to_inject)
|
||||
|
||||
if patched.closing:
|
||||
for arg_key, provider in patched.closing.items():
|
||||
if closings:
|
||||
for arg_key, provider in closings.items():
|
||||
if arg_key in kwargs and not isinstance(kwargs[arg_key], _Marker):
|
||||
continue
|
||||
if not isinstance(provider, providers.Resource):
|
||||
|
@ -36,7 +34,6 @@ def _get_sync_patched(fn, patched: PatchedCallable):
|
|||
provider.shutdown()
|
||||
|
||||
return result
|
||||
return _patched
|
||||
|
||||
|
||||
async def _async_inject(object fn, tuple args, dict kwargs, dict injections, dict closings):
|
||||
|
|
|
@ -982,7 +982,7 @@ _inspect_filter = InspectFilter()
|
|||
_loader = AutoLoader()
|
||||
|
||||
# Optimizations
|
||||
from ._cwiring import _get_sync_patched # noqa
|
||||
from ._cwiring import _sync_inject # noqa
|
||||
from ._cwiring import _async_inject # noqa
|
||||
|
||||
|
||||
|
@ -999,3 +999,15 @@ def _get_async_patched(fn: F, patched: PatchedCallable) -> F:
|
|||
patched.closing,
|
||||
)
|
||||
return _patched
|
||||
|
||||
def _get_sync_patched(fn: F, patched: PatchedCallable) -> F:
|
||||
@functools.wraps(fn)
|
||||
def _patched(*args, **kwargs):
|
||||
return _sync_inject(
|
||||
fn,
|
||||
args,
|
||||
kwargs,
|
||||
patched.injections,
|
||||
patched.closing,
|
||||
)
|
||||
return _patched
|
||||
|
|
Loading…
Reference in New Issue
Block a user