Dependency provider issue with abc (#267)

* Fix the issue

* Add the test

* Update tests

* Update changelog

* Update tests
This commit is contained in:
Roman Mogylatov 2020-07-22 12:14:26 -04:00 committed by GitHub
parent cfbed20a05
commit 1f115111b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3098 additions and 2978 deletions

View File

@ -7,6 +7,13 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_ follows `Semantic versioning`_
Development version
-------------------
- Fix an issue with creating ``Dependency`` provider with ``abc.ABCMeta``
(thanks to `awaizman1 <https://github.com/awaizman1>`_,
`issue #266 <https://github.com/ets-labs/python-dependency-injector/issues/266>`_,
`PR #267 <https://github.com/ets-labs/python-dependency-injector/pull/267>`_).
3.23.0 3.23.0
------ ------
- Add ``Flask`` tutorial. - Add ``Flask`` tutorial.

View File

@ -915,12 +915,12 @@ struct __pyx_obj_19dependency_injector_9providers_Delegate {
* *
* *
* cdef class Dependency(Provider): # <<<<<<<<<<<<<< * cdef class Dependency(Provider): # <<<<<<<<<<<<<<
* cdef type __instance_of * cdef object __instance_of
* *
*/ */
struct __pyx_obj_19dependency_injector_9providers_Dependency { struct __pyx_obj_19dependency_injector_9providers_Dependency {
struct __pyx_obj_19dependency_injector_9providers_Provider __pyx_base; struct __pyx_obj_19dependency_injector_9providers_Provider __pyx_base;
PyTypeObject *__pyx___instance_of; PyObject *__pyx___instance_of;
}; };
@ -1485,7 +1485,7 @@ static struct __pyx_vtabstruct_19dependency_injector_9providers_Delegate *__pyx_
* *
* *
* cdef class Dependency(Provider): # <<<<<<<<<<<<<< * cdef class Dependency(Provider): # <<<<<<<<<<<<<<
* cdef type __instance_of * cdef object __instance_of
* *
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -28,7 +28,7 @@ cdef class Delegate(Provider):
cdef class Dependency(Provider): cdef class Dependency(Provider):
cdef type __instance_of cdef object __instance_of
cdef class ExternalDependency(Dependency): cdef class ExternalDependency(Dependency):

View File

@ -419,8 +419,16 @@ cdef class Dependency(Provider):
:type: type :type: type
""" """
def __init__(self, type instance_of=object): def __init__(self, object instance_of=object):
"""Initializer.""" """Initializer."""
if not isinstance(instance_of, CLASS_TYPES):
raise TypeError(
'Argument \'instance_of\' has incorrect type (expected {0}, got {1}))'.format(
CLASS_TYPES,
instance_of,
)
)
self.__instance_of = instance_of self.__instance_of = instance_of
super(Dependency, self).__init__() super(Dependency, self).__init__()

View File

@ -249,6 +249,18 @@ class DependencyTests(unittest.TestCase):
def test_init_with_not_class(self): def test_init_with_not_class(self):
self.assertRaises(TypeError, providers.Dependency, object()) self.assertRaises(TypeError, providers.Dependency, object())
def test_with_abc(self):
try:
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc
provider = providers.Dependency(collections_abc.Mapping)
provider.provided_by(providers.Factory(dict))
self.assertIsInstance(provider(), collections_abc.Mapping)
self.assertIsInstance(provider(), dict)
def test_is_provider(self): def test_is_provider(self):
self.assertTrue(providers.is_provider(self.provider)) self.assertTrue(providers.is_provider(self.provider))