mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 03:36:41 +03:00
Add spike for providers copying
This commit is contained in:
parent
b4b93b4016
commit
fde062b9fc
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from copy import deepcopy
|
from dependency_injector.utils import _copy_providers
|
||||||
|
|
||||||
from dependency_injector.errors import UndefinedProviderError
|
from dependency_injector.errors import UndefinedProviderError
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ def copy(catalog):
|
||||||
else:
|
else:
|
||||||
memo[id(source_provider)] = provider
|
memo[id(source_provider)] = provider
|
||||||
|
|
||||||
copied_catalog.bind_providers(deepcopy(catalog.providers, memo),
|
copied_catalog.bind_providers(_copy_providers(catalog.providers, memo),
|
||||||
force=True)
|
force=True)
|
||||||
|
|
||||||
return copied_catalog
|
return copied_catalog
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Utils module."""
|
"""Utils module."""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import copy
|
||||||
|
import types
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -20,6 +22,12 @@ if _IS_PYPY or six.PY3: # pragma: no cover
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
_OBJECT_INIT = None
|
_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):
|
def is_provider(instance):
|
||||||
"""Check if instance is provider instance.
|
"""Check if instance is provider instance.
|
||||||
|
@ -245,3 +253,8 @@ def fetch_cls_init(cls):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return cls_init
|
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
Block a user