Merge branch 'release/4.11.3' into master

This commit is contained in:
Roman Mogylatov 2021-01-28 08:46:00 -05:00
commit 9225f9dcd6
6 changed files with 4157 additions and 4484 deletions

View File

@ -7,6 +7,13 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_
4.11.3
------
- Replace weakrefs with normal refs in ``ConfigurationOption`` to support
``Container().provider()`` use case. Test that it does not introduce a memory leak.
See issue: `#358#issuecomment-764482059 <https://github.com/ets-labs/python-dependency-injector/issues/358#issuecomment-764482059>`_.
Many thanks to `@Minitour <https://github.com/Minitour>`_ for reporting the issue.
4.11.2
------
- Fix a bug in ``providers.Container`` when it's declared not at class root level.

View File

@ -1,6 +1,6 @@
"""Top-level package."""
__version__ = '4.11.2'
__version__ = '4.11.3'
"""Version number.
:type: str

View File

@ -1087,12 +1087,12 @@ struct __pyx_obj_19dependency_injector_9providers_CoroutineDelegate {
* # Configuration providers
* cdef class ConfigurationOption(Provider): # <<<<<<<<<<<<<<
* cdef tuple __name
* cdef object __root_ref
* cdef Configuration __root
*/
struct __pyx_obj_19dependency_injector_9providers_ConfigurationOption {
struct __pyx_obj_19dependency_injector_9providers_Provider __pyx_base;
PyObject *__pyx___name;
PyObject *__pyx___root_ref;
struct __pyx_obj_19dependency_injector_9providers_Configuration *__pyx___root;
PyObject *__pyx___children;
int __pyx___required;
PyObject *__pyx___cache;
@ -1808,7 +1808,7 @@ static struct __pyx_vtabstruct_19dependency_injector_9providers_CoroutineDelegat
* # Configuration providers
* cdef class ConfigurationOption(Provider): # <<<<<<<<<<<<<<
* cdef tuple __name
* cdef object __root_ref
* cdef Configuration __root
*/
struct __pyx_vtabstruct_19dependency_injector_9providers_ConfigurationOption {

File diff suppressed because it is too large Load Diff

View File

@ -97,7 +97,7 @@ cdef class CoroutineDelegate(Delegate):
# Configuration providers
cdef class ConfigurationOption(Provider):
cdef tuple __name
cdef object __root_ref
cdef Configuration __root
cdef dict __children
cdef bint __required
cdef object __cache

View File

@ -1188,9 +1188,9 @@ cdef class ConfigurationOption(Provider):
:py:class:`Configuration` provider.
"""
def __init__(self, name, root, required=False):
def __init__(self, name, Configuration root, required=False):
self.__name = name
self.__root_ref = weakref.ref(root)
self.__root = root
self.__children = {}
self.__required = required
self.__cache = UNDEFINED
@ -1204,11 +1204,7 @@ cdef class ConfigurationOption(Provider):
return copied
copied_name = deepcopy(self.__name, memo)
root = self.__root_ref()
copied_root = memo.get(id(root))
if copied_root is None:
copied_root = deepcopy(root, memo)
copied_root = deepcopy(self.__root, memo)
copied = self.__class__(copied_name, copied_root, self.__required)
copied.__children = deepcopy(self.__children, memo)
@ -1228,7 +1224,7 @@ cdef class ConfigurationOption(Provider):
child = self.__children.get(item)
if child is None:
child_name = self.__name + (item,)
child = ConfigurationOption(child_name, self.__root_ref())
child = ConfigurationOption(child_name, self.__root)
self.__children[item] = child
return child
@ -1236,7 +1232,7 @@ cdef class ConfigurationOption(Provider):
child = self.__children.get(item)
if child is None:
child_name = self.__name + (item,)
child = ConfigurationOption(child_name, self.__root_ref())
child = ConfigurationOption(child_name, self.__root)
self.__children[item] = child
return child
@ -1245,8 +1241,7 @@ cdef class ConfigurationOption(Provider):
if self.__cache is not UNDEFINED:
return self.__cache
root = self.__root_ref()
value = root.get(self._get_self_name(), self.__required)
value = self.__root.get(self._get_self_name(), self.__required)
self.__cache = value
return value
@ -1257,11 +1252,10 @@ cdef class ConfigurationOption(Provider):
@property
def root(self):
return self.__root_ref()
return self.__root
def get_name(self):
root = self.__root_ref()
return '.'.join((root.get_name(), self._get_self_name()))
return '.'.join((self.__root.get_name(), self._get_self_name()))
def get_name_segments(self):
return self.__name
@ -1276,7 +1270,7 @@ cdef class ConfigurationOption(Provider):
return TypedConfigurationOption(callback, self, *args, **kwargs)
def required(self):
return self.__class__(self.__name, self.__root_ref(), required=True)
return self.__class__(self.__name, self.__root, required=True)
def is_required(self):
return self.__required
@ -1284,8 +1278,7 @@ cdef class ConfigurationOption(Provider):
def override(self, value):
if isinstance(value, Provider):
raise Error('Configuration option can only be overridden by a value')
root = self.__root_ref()
return root.set(self._get_self_name(), value)
return self.__root.set(self._get_self_name(), value)
def reset_last_overriding(self):
raise Error('Configuration option does not support this method')
@ -1440,13 +1433,7 @@ cdef class ConfigurationOption(Provider):
self.override(value)
def _is_strict_mode_enabled(self):
cdef Configuration root
root = self.__root_ref()
if not root:
return False
return root.__strict
return self.__root.__strict
cdef class TypedConfigurationOption(Callable):