Merge branch 'release/4.31.2' into master

This commit is contained in:
Roman Mogylatov 2021-03-30 14:02:22 -06:00
commit 155f598699
7 changed files with 3306 additions and 2926 deletions

View File

@ -16,3 +16,4 @@ Dependency Injector Contributors
+ Dmitry Rassoshenko (rda-dev)
+ Fotis Koutoupas (kootoopas)
+ Shubhendra Singh Chauhan (withshubh)
+ sonthonaxrk (sonthonaxrk)

View File

@ -7,6 +7,15 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_
4.31.2
------
- Fix an issue with ``Dict`` provider non-string keys.
See issue: `#435 <https://github.com/ets-labs/python-dependency-injector/issues/435>`_.
Thanks to `@daniel55411 <https://github.com/daniel55411>`_ for reporting the issue.
- Fix Flask scoped contexts example.
See issue: `#440 <https://github.com/ets-labs/python-dependency-injector/pull/440>`_.
Thanks to `@sonthonaxrk <https://github.com/sonthonaxrk>`_ for the contribution.
4.31.1
------
- Fix ``ThreadSafeSingleton`` synchronization issue.

View File

@ -10,7 +10,7 @@ class Service:
class Container(containers.DeclarativeContainer):
service_provider = providers.Singleton(Service)
service_provider = providers.ThreadLocalSingleton(Service)
def index_view():

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -3169,7 +3169,7 @@ cdef class Dict(Provider):
return copied
copied = _memorized_duplicate(self, memo)
copied.set_kwargs(**deepcopy(self.kwargs, memo))
self._copy_kwargs(copied, memo)
self._copy_overridings(copied, memo)
return copied
@ -3238,11 +3238,20 @@ cdef class Dict(Provider):
yield from filter(is_provider, self.kwargs.values())
yield from super().related
def _copy_kwargs(self, copied, memo):
"""Return copy of kwargs."""
copied_kwargs = {
_copy_if_provider(name, memo): _copy_if_provider(value, memo)
for name, value in self.kwargs.items()
}
copied.set_kwargs(copied_kwargs)
cpdef object _provide(self, tuple args, dict kwargs):
"""Return result of provided callable's call."""
return __provide_keyword_args(kwargs, self.__kwargs, self.__kwargs_len)
cdef class Resource(Provider):
"""Resource provider provides a component with initialization and shutdown."""

View File

@ -173,6 +173,27 @@ class DictTests(unittest.TestCase):
self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls)
self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_kwargs_non_string_keys(self):
a1 = object()
a2 = object()
dependent_provider1 = providers.Factory(list)
dependent_provider2 = providers.Factory(dict)
provider = providers.Dict({a1: dependent_provider1, a2: dependent_provider2})
provider_copy = providers.deepcopy(provider)
dependent_provider_copy1 = provider_copy.kwargs[a1]
dependent_provider_copy2 = provider_copy.kwargs[a2]
self.assertNotEqual(provider.kwargs, provider_copy.kwargs)
self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls)
self.assertIsNot(dependent_provider1, dependent_provider_copy1)
self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls)
self.assertIsNot(dependent_provider2, dependent_provider_copy2)
def test_deepcopy_overridden(self):
provider = providers.Dict()
object_provider = providers.Object(object())