mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-23 01:56:58 +03:00
Merge branch 'release/3.12.4' into master
This commit is contained in:
commit
8cc00dee83
|
@ -7,6 +7,11 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
3.12.4
|
||||
------
|
||||
- Fix bug `#200 <https://github.com/ets-labs/python-dependency-injector/issues/200>`_.
|
||||
- Make some refactoring `#199 <https://github.com/ets-labs/python-dependency-injector/issues/199>`_.
|
||||
|
||||
3.12.3
|
||||
------
|
||||
- Fix bug `#198 <https://github.com/ets-labs/python-dependency-injector/issues/198>`_.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Dependency injector top-level package."""
|
||||
|
||||
__version__ = '3.12.3'
|
||||
__version__ = '3.12.4'
|
||||
"""Version number that follows semantic versioning.
|
||||
|
||||
:type: str
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -10,7 +10,6 @@ cimport cython
|
|||
cdef class Provider(object):
|
||||
cdef tuple __overridden
|
||||
cdef Provider __last_overriding
|
||||
cdef object __overriding_lock
|
||||
|
||||
cpdef object _provide(self, tuple args, dict kwargs)
|
||||
cpdef void _copy_overridings(self, Provider copied, dict memo)
|
||||
|
|
|
@ -87,7 +87,6 @@ cdef class Provider(object):
|
|||
"""Initializer."""
|
||||
self.__overridden = tuple()
|
||||
self.__last_overriding = None
|
||||
self.__overriding_lock = self.__class__.overriding_lock
|
||||
super(Provider, self).__init__()
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
|
@ -128,7 +127,7 @@ cdef class Provider(object):
|
|||
@property
|
||||
def overridden(self):
|
||||
"""Return tuple of overriding providers."""
|
||||
with self.__overriding_lock:
|
||||
with self.overriding_lock:
|
||||
return self.__overridden
|
||||
|
||||
@property
|
||||
|
@ -157,7 +156,7 @@ cdef class Provider(object):
|
|||
if not is_provider(provider):
|
||||
provider = Object(provider)
|
||||
|
||||
with self.__overriding_lock:
|
||||
with self.overriding_lock:
|
||||
self.__overridden += (provider,)
|
||||
self.__last_overriding = provider
|
||||
|
||||
|
@ -171,7 +170,7 @@ cdef class Provider(object):
|
|||
|
||||
:rtype: None
|
||||
"""
|
||||
with self.__overriding_lock:
|
||||
with self.overriding_lock:
|
||||
if len(self.__overridden) == 0:
|
||||
raise Error('Provider {0} is not overridden'.format(str(self)))
|
||||
|
||||
|
@ -186,7 +185,7 @@ cdef class Provider(object):
|
|||
|
||||
:rtype: None
|
||||
"""
|
||||
with self.__overriding_lock:
|
||||
with self.overriding_lock:
|
||||
self.__overridden = tuple()
|
||||
self.__last_overriding = None
|
||||
|
||||
|
@ -652,7 +651,11 @@ cdef class Callable(Provider):
|
|||
if copied is not None:
|
||||
return copied
|
||||
|
||||
copied = self.__class__(self.provides,
|
||||
provides = self.provides
|
||||
if isinstance(provides, Provider):
|
||||
provides = deepcopy(provides, memo)
|
||||
|
||||
copied = self.__class__(provides,
|
||||
*deepcopy(self.args, memo),
|
||||
**deepcopy(self.kwargs, memo))
|
||||
|
||||
|
@ -1098,7 +1101,11 @@ cdef class Factory(Provider):
|
|||
if copied is not None:
|
||||
return copied
|
||||
|
||||
copied = self.__class__(self.cls,
|
||||
cls = self.cls
|
||||
if isinstance(cls, Provider):
|
||||
cls = deepcopy(cls, memo)
|
||||
|
||||
copied = self.__class__(cls,
|
||||
*deepcopy(self.args, memo),
|
||||
**deepcopy(self.kwargs, memo))
|
||||
copied.set_attributes(**deepcopy(self.attributes, memo))
|
||||
|
@ -1446,7 +1453,11 @@ cdef class BaseSingleton(Provider):
|
|||
if copied is not None:
|
||||
return copied
|
||||
|
||||
copied = self.__class__(self.cls,
|
||||
cls = self.cls
|
||||
if isinstance(cls, Provider):
|
||||
cls = deepcopy(cls, memo)
|
||||
|
||||
copied = self.__class__(cls,
|
||||
*deepcopy(self.args, memo),
|
||||
**deepcopy(self.kwargs, memo))
|
||||
copied.set_attributes(**deepcopy(self.attributes, memo))
|
||||
|
|
|
@ -279,7 +279,7 @@ class DeclarativeContainerTests(unittest.TestCase):
|
|||
# Bug:
|
||||
# https://github.com/ets-labs/python-dependency-injector/issues/198
|
||||
class _Container(containers.DeclarativeContainer):
|
||||
p1 = providers.Object(1)
|
||||
p1 = providers.Dependency(instance_of=int)
|
||||
|
||||
p2 = providers.Dependency(object)
|
||||
p2.override(providers.Factory(dict, p1=p1))
|
||||
|
@ -299,3 +299,17 @@ class DeclarativeContainerTests(unittest.TestCase):
|
|||
_Container.p2.last_overriding.kwargs['p1'],
|
||||
_Container.p1,
|
||||
)
|
||||
|
||||
def test_init_with_chained_dependency(self):
|
||||
# Bug:
|
||||
# https://github.com/ets-labs/python-dependency-injector/issues/200
|
||||
class _Container(containers.DeclarativeContainer):
|
||||
p1 = providers.Dependency(instance_of=int)
|
||||
p2 = providers.Factory(p1)
|
||||
|
||||
container = _Container(p1=1)
|
||||
|
||||
self.assertEqual(container.p2(), 1)
|
||||
self.assertIs(container.p2.cls, container.p1)
|
||||
self.assertIs(_Container.p2.cls, _Container.p1)
|
||||
self.assertIsNot(container.p2.cls, _Container.p1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user