diff --git a/src/dependency_injector/providers.c b/src/dependency_injector/providers.c index ef016584..3375f543 100644 --- a/src/dependency_injector/providers.c +++ b/src/dependency_injector/providers.c @@ -31149,11 +31149,11 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_20ThreadLocalSingleto /* "dependency_injector/providers.pyx":1811 * :rtype: None * """ - * self.__storage.instance = None # <<<<<<<<<<<<<< + * del self.__storage.instance # <<<<<<<<<<<<<< * * cpdef object _provide(self, tuple args, dict kwargs): */ - if (__Pyx_PyObject_SetAttrStr(__pyx_v_self->__pyx___storage, __pyx_n_s_instance, Py_None) < 0) __PYX_ERR(1, 1811, __pyx_L1_error) + if (__Pyx_PyObject_DelAttrStr(__pyx_v_self->__pyx___storage, __pyx_n_s_instance) < 0) __PYX_ERR(1, 1811, __pyx_L1_error) /* "dependency_injector/providers.pyx":1806 * super(ThreadLocalSingleton, self).__init__(provides, *args, **kwargs) @@ -31176,7 +31176,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_20ThreadLocalSingleto } /* "dependency_injector/providers.pyx":1813 - * self.__storage.instance = None + * del self.__storage.instance * * cpdef object _provide(self, tuple args, dict kwargs): # <<<<<<<<<<<<<< * """Return single instance.""" @@ -31461,7 +31461,7 @@ static PyObject *__pyx_f_19dependency_injector_9providers_20ThreadLocalSingleton } /* "dependency_injector/providers.pyx":1813 - * self.__storage.instance = None + * del self.__storage.instance * * cpdef object _provide(self, tuple args, dict kwargs): # <<<<<<<<<<<<<< * """Return single instance.""" diff --git a/src/dependency_injector/providers.pyx b/src/dependency_injector/providers.pyx index b2507974..91c0ab59 100644 --- a/src/dependency_injector/providers.pyx +++ b/src/dependency_injector/providers.pyx @@ -1808,7 +1808,7 @@ cdef class ThreadLocalSingleton(BaseSingleton): :rtype: None """ - self.__storage.instance = None + del self.__storage.instance cpdef object _provide(self, tuple args, dict kwargs): """Return single instance.""" diff --git a/tests/unit/providers/test_singletons_py2_py3.py b/tests/unit/providers/test_singletons_py2_py3.py index fcfb64ce..52ad1360 100644 --- a/tests/unit/providers/test_singletons_py2_py3.py +++ b/tests/unit/providers/test_singletons_py2_py3.py @@ -347,7 +347,7 @@ class _BaseSingletonTestCase(object): provider.reset() instance2 = provider() - self.assertIsInstance(instance1, object) + self.assertIsInstance(instance2, object) self.assertIsNot(instance1, instance2) @@ -397,6 +397,19 @@ class ThreadLocalSingletonTests(_BaseSingletonTestCase, unittest.TestCase): repr(Example), hex(id(provider)))) + def test_reset(self): + provider = providers.ThreadLocalSingleton(Example) + + instance1 = provider() + self.assertIsInstance(instance1, Example) + + provider.reset() + + instance2 = provider() + self.assertIsInstance(instance2, Example) + + self.assertIsNot(instance1, instance2) + class DelegatedThreadLocalSingletonTests(_BaseSingletonTestCase, unittest.TestCase):