mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-28 12:33:59 +03:00
Wiring changes
This commit is contained in:
parent
b4fb9a7178
commit
09cf3459c5
File diff suppressed because it is too large
Load Diff
|
@ -6,6 +6,7 @@ import sys
|
|||
import types
|
||||
|
||||
from . import providers
|
||||
from .wiring import _Marker
|
||||
|
||||
|
||||
if sys.version_info[0] == 3: # pragma: no cover
|
||||
|
@ -22,7 +23,10 @@ else: # pragma: no cover
|
|||
def _get_sync_patched(fn):
|
||||
@functools.wraps(fn)
|
||||
def _patched(*args, **kwargs):
|
||||
cdef dict to_inject = kwargs.copy()
|
||||
cdef object result
|
||||
cdef dict to_inject
|
||||
|
||||
to_inject = kwargs.copy()
|
||||
for injection, provider in _patched.__injections__.items():
|
||||
if injection not in kwargs \
|
||||
or _is_fastapi_default_arg_injection(injection, kwargs):
|
||||
|
@ -30,13 +34,14 @@ def _get_sync_patched(fn):
|
|||
|
||||
result = fn(*args, **to_inject)
|
||||
|
||||
for injection, provider in _patched.__closing__.items():
|
||||
if injection in kwargs \
|
||||
and not _is_fastapi_default_arg_injection(injection, kwargs):
|
||||
continue
|
||||
if not isinstance(provider, providers.Resource):
|
||||
continue
|
||||
provider.shutdown()
|
||||
if _patched.__closing__:
|
||||
for injection, provider in _patched.__closing__.items():
|
||||
if injection in kwargs \
|
||||
and not _is_fastapi_default_arg_injection(injection, kwargs):
|
||||
continue
|
||||
if not isinstance(provider, providers.Resource):
|
||||
continue
|
||||
provider.shutdown()
|
||||
|
||||
return result
|
||||
return _patched
|
||||
|
@ -44,8 +49,4 @@ def _get_sync_patched(fn):
|
|||
|
||||
cdef bint _is_fastapi_default_arg_injection(object injection, dict kwargs):
|
||||
"""Check if injection is FastAPI injection of the default argument."""
|
||||
return injection in kwargs and _is_marker(kwargs[injection])
|
||||
|
||||
|
||||
cdef bint _is_marker(object instance):
|
||||
return getattr(instance, "__IS_MARKER__", False) is True
|
||||
return injection in kwargs and isinstance(kwargs[injection], _Marker)
|
||||
|
|
|
@ -58,7 +58,6 @@ except ImportError:
|
|||
|
||||
from . import providers
|
||||
|
||||
|
||||
if sys.version_info[:2] == (3, 5):
|
||||
warnings.warn(
|
||||
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
|
||||
|
@ -600,31 +599,6 @@ def _get_patched(fn, reference_injections, reference_closing):
|
|||
return patched
|
||||
|
||||
|
||||
from ._cwiring import _get_sync_patched
|
||||
|
||||
# def _get_sync_patched(fn):
|
||||
# @functools.wraps(fn)
|
||||
# def _patched(*args, **kwargs):
|
||||
# to_inject = kwargs.copy()
|
||||
# for injection, provider in _patched.__injections__.items():
|
||||
# if injection not in kwargs \
|
||||
# or _is_fastapi_default_arg_injection(injection, kwargs):
|
||||
# to_inject[injection] = provider()
|
||||
#
|
||||
# result = fn(*args, **to_inject)
|
||||
#
|
||||
# for injection, provider in _patched.__closing__.items():
|
||||
# if injection in kwargs \
|
||||
# and not _is_fastapi_default_arg_injection(injection, kwargs):
|
||||
# continue
|
||||
# if not isinstance(provider, providers.Resource):
|
||||
# continue
|
||||
# provider.shutdown()
|
||||
#
|
||||
# return result
|
||||
# return _patched
|
||||
|
||||
|
||||
def _get_async_patched(fn):
|
||||
@functools.wraps(fn)
|
||||
async def _patched(*args, **kwargs):
|
||||
|
@ -962,3 +936,6 @@ def is_loader_installed() -> bool:
|
|||
_patched_registry = PatchedRegistry()
|
||||
_inspect_filter = InspectFilter()
|
||||
_loader = AutoLoader()
|
||||
|
||||
# Optimizations
|
||||
from ._cwiring import _get_sync_patched # noqa
|
||||
|
|
Loading…
Reference in New Issue
Block a user