From 0f3e1707112cfee6b3a90971ae50f1ce62063476 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sun, 25 Apr 2021 13:45:34 -0400 Subject: [PATCH] Bump version to 4.32.1 --- docs/main/changelog.rst | 7 +++++ src/dependency_injector/__init__.py | 2 +- src/dependency_injector/providers.c | 13 +++----- src/dependency_injector/providers.pyx | 2 +- tests/unit/providers/test_async_py36.py | 41 +++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index ee5e1a11..442e043c 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,13 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ +4.32.1 +------ +- Fix a bug with ``List`` provider not working in async mode. + See issue: `#450 `_. + Thanks to `@mxab `_ for reporting the issue. +- Add async mode tests for ``List`` and ``Dict`` provider. + 4.32.0 ------ - Add ``ContextLocalSingleton`` provider. diff --git a/src/dependency_injector/__init__.py b/src/dependency_injector/__init__.py index c470681b..941708f7 100644 --- a/src/dependency_injector/__init__.py +++ b/src/dependency_injector/__init__.py @@ -1,6 +1,6 @@ """Top-level package.""" -__version__ = '4.32.0' +__version__ = '4.32.1' """Version number. :type: str diff --git a/src/dependency_injector/providers.c b/src/dependency_injector/providers.c index de04deea..0aa8661f 100644 --- a/src/dependency_injector/providers.c +++ b/src/dependency_injector/providers.c @@ -62896,7 +62896,7 @@ static PyObject *__pyx_gb_19dependency_injector_9providers_4List_7related_2gener * * cpdef object _provide(self, tuple args, dict kwargs): # <<<<<<<<<<<<<< * """Return result of provided callable's call.""" - * return list(__provide_positional_args(args, self.__args, self.__args_len)) + * return __provide_positional_args(args, self.__args, self.__args_len) */ static PyObject *__pyx_pw_19dependency_injector_9providers_4List_13_provide(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ @@ -62993,7 +62993,7 @@ static PyObject *__pyx_f_19dependency_injector_9providers_4List__provide(struct /* "dependency_injector/providers.pyx":3214 * cpdef object _provide(self, tuple args, dict kwargs): * """Return result of provided callable's call.""" - * return list(__provide_positional_args(args, self.__args, self.__args_len)) # <<<<<<<<<<<<<< + * return __provide_positional_args(args, self.__args, self.__args_len) # <<<<<<<<<<<<<< * * */ @@ -63003,11 +63003,8 @@ static PyObject *__pyx_f_19dependency_injector_9providers_4List__provide(struct __pyx_t_2 = __pyx_f_19dependency_injector_9providers___provide_positional_args(__pyx_v_args, ((PyObject*)__pyx_t_1), __pyx_v_self->__pyx___args_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3214, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; /* "dependency_injector/providers.pyx":3212 @@ -63015,7 +63012,7 @@ static PyObject *__pyx_f_19dependency_injector_9providers_4List__provide(struct * * cpdef object _provide(self, tuple args, dict kwargs): # <<<<<<<<<<<<<< * """Return result of provided callable's call.""" - * return list(__provide_positional_args(args, self.__args, self.__args_len)) + * return __provide_positional_args(args, self.__args, self.__args_len) */ /* function exit code */ diff --git a/src/dependency_injector/providers.pyx b/src/dependency_injector/providers.pyx index c9b74cf0..579ce5e7 100644 --- a/src/dependency_injector/providers.pyx +++ b/src/dependency_injector/providers.pyx @@ -3211,7 +3211,7 @@ cdef class List(Provider): cpdef object _provide(self, tuple args, dict kwargs): """Return result of provided callable's call.""" - return list(__provide_positional_args(args, self.__args, self.__args_len)) + return __provide_positional_args(args, self.__args, self.__args_len) cdef class Dict(Provider): diff --git a/tests/unit/providers/test_async_py36.py b/tests/unit/providers/test_async_py36.py index a971ff03..a784da14 100644 --- a/tests/unit/providers/test_async_py36.py +++ b/tests/unit/providers/test_async_py36.py @@ -868,6 +868,47 @@ class DependencyTests(AsyncTestCase): self.assertEqual(dependency4, dependency) +class ListTests(AsyncTestCase): + + def test_provide(self): + # See issue: https://github.com/ets-labs/python-dependency-injector/issues/450 + async def create_resource(param: str): + return param + + class Container(containers.DeclarativeContainer): + + resources = providers.List( + providers.Resource(create_resource, 'foo'), + providers.Resource(create_resource, 'bar') + ) + + container = Container() + resources = self._run(container.resources()) + + self.assertEqual(resources[0], 'foo') + self.assertEqual(resources[1], 'bar') + + +class DictTests(AsyncTestCase): + + def test_provide(self): + async def create_resource(param: str): + return param + + class Container(containers.DeclarativeContainer): + + resources = providers.Dict( + foo=providers.Resource(create_resource, 'foo'), + bar=providers.Resource(create_resource, 'bar') + ) + + container = Container() + resources = self._run(container.resources()) + + self.assertEqual(resources['foo'], 'foo') + self.assertEqual(resources['bar'], 'bar') + + class OverrideTests(AsyncTestCase): def test_provider(self):