mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
Removing of Factory restriction to operate with class types only, factory methods are valid now
This commit is contained in:
parent
040aad93f8
commit
2c2d4f7434
|
@ -101,8 +101,8 @@ class Factory(Provider):
|
|||
|
||||
def __init__(self, provides, *injections):
|
||||
"""Initializer."""
|
||||
if not isinstance(provides, class_types):
|
||||
raise Error('Factory provider expects to get class, ' +
|
||||
if not callable(provides):
|
||||
raise Error('Factory provider expects to get callable, ' +
|
||||
'got {0} instead'.format(str(provides)))
|
||||
self._provides = provides
|
||||
self._kwargs = tuple((injection
|
||||
|
@ -151,10 +151,10 @@ class Singleton(Provider):
|
|||
|
||||
__slots__ = ('_instance', '_factory')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, provides, *injections):
|
||||
"""Initializer."""
|
||||
self._instance = None
|
||||
self._factory = Factory(*args, **kwargs)
|
||||
self._factory = Factory(provides, *injections)
|
||||
super(Singleton, self).__init__()
|
||||
|
||||
def _provide(self, *args, **kwargs):
|
||||
|
|
|
@ -186,8 +186,12 @@ class FactoryTests(unittest.TestCase):
|
|||
"""Test `is_provider` check."""
|
||||
self.assertTrue(is_provider(Factory(self.Example)))
|
||||
|
||||
def test_init_with_not_class(self):
|
||||
"""Test creation of provider with not a class."""
|
||||
def test_init_with_callable(self):
|
||||
"""Test creation of provider with a callable."""
|
||||
self.assertTrue(Factory(credits))
|
||||
|
||||
def test_init_with_not_callable(self):
|
||||
"""Test creation of provider with not a callable."""
|
||||
self.assertRaises(Error, Factory, 123)
|
||||
|
||||
def test_call(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user