mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 18:43:58 +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
|
import types
|
||||||
|
|
||||||
from . import providers
|
from . import providers
|
||||||
|
from .wiring import _Marker
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] == 3: # pragma: no cover
|
if sys.version_info[0] == 3: # pragma: no cover
|
||||||
|
@ -22,7 +23,10 @@ else: # pragma: no cover
|
||||||
def _get_sync_patched(fn):
|
def _get_sync_patched(fn):
|
||||||
@functools.wraps(fn)
|
@functools.wraps(fn)
|
||||||
def _patched(*args, **kwargs):
|
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():
|
for injection, provider in _patched.__injections__.items():
|
||||||
if injection not in kwargs \
|
if injection not in kwargs \
|
||||||
or _is_fastapi_default_arg_injection(injection, kwargs):
|
or _is_fastapi_default_arg_injection(injection, kwargs):
|
||||||
|
@ -30,6 +34,7 @@ def _get_sync_patched(fn):
|
||||||
|
|
||||||
result = fn(*args, **to_inject)
|
result = fn(*args, **to_inject)
|
||||||
|
|
||||||
|
if _patched.__closing__:
|
||||||
for injection, provider in _patched.__closing__.items():
|
for injection, provider in _patched.__closing__.items():
|
||||||
if injection in kwargs \
|
if injection in kwargs \
|
||||||
and not _is_fastapi_default_arg_injection(injection, kwargs):
|
and not _is_fastapi_default_arg_injection(injection, kwargs):
|
||||||
|
@ -44,8 +49,4 @@ def _get_sync_patched(fn):
|
||||||
|
|
||||||
cdef bint _is_fastapi_default_arg_injection(object injection, dict kwargs):
|
cdef bint _is_fastapi_default_arg_injection(object injection, dict kwargs):
|
||||||
"""Check if injection is FastAPI injection of the default argument."""
|
"""Check if injection is FastAPI injection of the default argument."""
|
||||||
return injection in kwargs and _is_marker(kwargs[injection])
|
return injection in kwargs and isinstance(kwargs[injection], _Marker)
|
||||||
|
|
||||||
|
|
||||||
cdef bint _is_marker(object instance):
|
|
||||||
return getattr(instance, "__IS_MARKER__", False) is True
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ except ImportError:
|
||||||
|
|
||||||
from . import providers
|
from . import providers
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[:2] == (3, 5):
|
if sys.version_info[:2] == (3, 5):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Dependency Injector will drop support of Python 3.5 after Jan 1st of 2022. "
|
"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
|
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):
|
def _get_async_patched(fn):
|
||||||
@functools.wraps(fn)
|
@functools.wraps(fn)
|
||||||
async def _patched(*args, **kwargs):
|
async def _patched(*args, **kwargs):
|
||||||
|
@ -962,3 +936,6 @@ def is_loader_installed() -> bool:
|
||||||
_patched_registry = PatchedRegistry()
|
_patched_registry = PatchedRegistry()
|
||||||
_inspect_filter = InspectFilter()
|
_inspect_filter = InspectFilter()
|
||||||
_loader = AutoLoader()
|
_loader = AutoLoader()
|
||||||
|
|
||||||
|
# Optimizations
|
||||||
|
from ._cwiring import _get_sync_patched # noqa
|
||||||
|
|
Loading…
Reference in New Issue
Block a user