mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
Fix bug #200
This commit is contained in:
parent
4bfaf92099
commit
461c546d31
File diff suppressed because it is too large
Load Diff
|
@ -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))
|
||||
|
|
|
@ -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