This commit is contained in:
Roman Mogylatov 2018-07-26 10:16:02 +03:00
parent 4bfaf92099
commit 461c546d31
3 changed files with 1908 additions and 1741 deletions

File diff suppressed because it is too large Load Diff

View File

@ -652,7 +652,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 +1102,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 +1454,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))

View File

@ -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)