Add spike for providers copying
This commit is contained in:
parent
b4b93b4016
commit
fde062b9fc
|
@ -2,8 +2,7 @@
|
|||
|
||||
import six
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from dependency_injector.utils import _copy_providers
|
||||
from dependency_injector.errors import UndefinedProviderError
|
||||
|
||||
|
||||
|
@ -40,7 +39,7 @@ def copy(catalog):
|
|||
else:
|
||||
memo[id(source_provider)] = provider
|
||||
|
||||
copied_catalog.bind_providers(deepcopy(catalog.providers, memo),
|
||||
copied_catalog.bind_providers(_copy_providers(catalog.providers, memo),
|
||||
force=True)
|
||||
|
||||
return copied_catalog
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Utils module."""
|
||||
|
||||
import sys
|
||||
import copy
|
||||
import types
|
||||
import threading
|
||||
|
||||
import six
|
||||
|
@ -20,6 +22,12 @@ if _IS_PYPY or six.PY3: # pragma: no cover
|
|||
else: # pragma: no cover
|
||||
_OBJECT_INIT = None
|
||||
|
||||
if six.PY2: # pragma: no cover
|
||||
copy._deepcopy_dispatch[types.MethodType] = \
|
||||
lambda obj, memo: type(obj)(obj.im_func,
|
||||
copy.deepcopy(obj.im_self, memo),
|
||||
obj.im_class)
|
||||
|
||||
|
||||
def is_provider(instance):
|
||||
"""Check if instance is provider instance.
|
||||
|
@ -245,3 +253,8 @@ def fetch_cls_init(cls):
|
|||
return None
|
||||
else:
|
||||
return cls_init
|
||||
|
||||
|
||||
def _copy_providers(providers, memo=None):
|
||||
"""Make full copy of providers dictionary."""
|
||||
return copy.deepcopy(providers, memo)
|
||||
|
|
Loading…
Reference in New Issue