mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Merge branch 'release/3.6.0' into master
This commit is contained in:
commit
fa120b2a31
|
@ -7,6 +7,12 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
3.6.0
|
||||
-----
|
||||
- Add ``CallableDelegate`` provider.
|
||||
- Add ``FactoryDelegate`` provider.
|
||||
- Add ``SingletonDelegate`` provider.
|
||||
|
||||
3.5.0
|
||||
-----
|
||||
- Add functionality for initializing ``Configuration`` provider with default
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Dependency injector top-level package."""
|
||||
|
||||
__version__ = '3.5.0'
|
||||
__version__ = '3.6.0'
|
||||
"""Version number that follows semantic versioning.
|
||||
|
||||
:type: str
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -55,6 +55,10 @@ cdef class AbstractCallable(Callable):
|
|||
cpdef object _provide(self, tuple args, dict kwargs)
|
||||
|
||||
|
||||
cdef class CallableDelegate(Delegate):
|
||||
pass
|
||||
|
||||
|
||||
# Configuration providers
|
||||
cdef class Configuration(Provider):
|
||||
cdef str __name
|
||||
|
@ -85,6 +89,10 @@ cdef class AbstractFactory(Factory):
|
|||
cpdef object _provide(self, tuple args, dict kwargs)
|
||||
|
||||
|
||||
cdef class FactoryDelegate(Delegate):
|
||||
pass
|
||||
|
||||
|
||||
# Singleton providers
|
||||
cdef class BaseSingleton(Provider):
|
||||
cdef Factory __instantiator
|
||||
|
@ -125,6 +133,10 @@ cdef class AbstractSingleton(BaseSingleton):
|
|||
pass
|
||||
|
||||
|
||||
cdef class SingletonDelegate(Delegate):
|
||||
pass
|
||||
|
||||
|
||||
# Injections
|
||||
cdef class Injection(object):
|
||||
cdef object __value
|
||||
|
|
|
@ -647,6 +647,28 @@ cdef class AbstractCallable(Callable):
|
|||
'to overriding provider')
|
||||
|
||||
|
||||
cdef class CallableDelegate(Delegate):
|
||||
"""Callable delegate injects delegating callable "as is".
|
||||
|
||||
.. py:attribute:: provides
|
||||
|
||||
Value that have to be provided.
|
||||
|
||||
:type: object
|
||||
"""
|
||||
|
||||
def __init__(self, callable):
|
||||
"""Initializer.
|
||||
|
||||
:param callable: Value that have to be provided.
|
||||
:type callable: object
|
||||
"""
|
||||
if isinstance(callable, Callable) is False:
|
||||
raise Error('{0} can wrap only {1} providers'.format(
|
||||
self.__class__, Callable))
|
||||
super(Delegate, self).__init__(callable)
|
||||
|
||||
|
||||
cdef class Configuration(Provider):
|
||||
"""Configuration provider.
|
||||
|
||||
|
@ -1066,6 +1088,29 @@ cdef class AbstractFactory(Factory):
|
|||
raise NotImplementedError('Abstract provider forward providing logic '
|
||||
'to overriding provider')
|
||||
|
||||
|
||||
cdef class FactoryDelegate(Delegate):
|
||||
"""Factory delegate injects delegating factory "as is".
|
||||
|
||||
.. py:attribute:: provides
|
||||
|
||||
Value that have to be provided.
|
||||
|
||||
:type: object
|
||||
"""
|
||||
|
||||
def __init__(self, factory):
|
||||
"""Initializer.
|
||||
|
||||
:param factory: Value that have to be provided.
|
||||
:type factory: object
|
||||
"""
|
||||
if isinstance(factory, Factory) is False:
|
||||
raise Error('{0} can wrap only {1} providers'.format(
|
||||
self.__class__, Factory))
|
||||
super(Delegate, self).__init__(factory)
|
||||
|
||||
|
||||
cdef class BaseSingleton(Provider):
|
||||
"""Base class of singleton providers."""
|
||||
|
||||
|
@ -1503,6 +1548,28 @@ cdef class AbstractSingleton(BaseSingleton):
|
|||
return self.__last_overriding.reset()
|
||||
|
||||
|
||||
cdef class SingletonDelegate(Delegate):
|
||||
"""Singleton delegate injects delegating singleton "as is".
|
||||
|
||||
.. py:attribute:: provides
|
||||
|
||||
Value that have to be provided.
|
||||
|
||||
:type: object
|
||||
"""
|
||||
|
||||
def __init__(self, singleton):
|
||||
"""Initializer.
|
||||
|
||||
:param singleton: Value that have to be provided.
|
||||
:type singleton: py:class:`BaseSingleton`
|
||||
"""
|
||||
if isinstance(singleton, BaseSingleton) is False:
|
||||
raise Error('{0} can wrap only {1} providers'.format(
|
||||
self.__class__, BaseSingleton))
|
||||
super(Delegate, self).__init__(singleton)
|
||||
|
||||
|
||||
cdef class Injection(object):
|
||||
"""Abstract injection class."""
|
||||
|
||||
|
|
|
@ -251,3 +251,18 @@ class AbstractCallableTests(unittest.TestCase):
|
|||
'AbstractCallable({0}) at {1}>'.format(
|
||||
repr(_example),
|
||||
hex(id(provider))))
|
||||
|
||||
|
||||
class CallableDelegateTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.delegated = providers.Callable(_example)
|
||||
self.delegate = providers.CallableDelegate(self.delegated)
|
||||
|
||||
def test_is_delegate(self):
|
||||
self.assertIsInstance(self.delegate, providers.Delegate)
|
||||
|
||||
def test_init_with_not_callable(self):
|
||||
self.assertRaises(errors.Error,
|
||||
providers.CallableDelegate,
|
||||
providers.Object(object()))
|
||||
|
|
|
@ -399,3 +399,18 @@ class AbstractFactoryTests(unittest.TestCase):
|
|||
'AbstractFactory({0}) at {1}>'.format(
|
||||
repr(Example),
|
||||
hex(id(provider))))
|
||||
|
||||
|
||||
class FactoryDelegateTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.delegated = providers.Factory(object)
|
||||
self.delegate = providers.FactoryDelegate(self.delegated)
|
||||
|
||||
def test_is_delegate(self):
|
||||
self.assertIsInstance(self.delegate, providers.Delegate)
|
||||
|
||||
def test_init_with_not_factory(self):
|
||||
self.assertRaises(errors.Error,
|
||||
providers.FactoryDelegate,
|
||||
providers.Object(object()))
|
||||
|
|
|
@ -492,3 +492,18 @@ class AbstractSingletonTests(unittest.TestCase):
|
|||
'AbstractSingleton({0}) at {1}>'.format(
|
||||
repr(Example),
|
||||
hex(id(provider))))
|
||||
|
||||
|
||||
class SingletonDelegateTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.delegated = providers.Singleton(Example)
|
||||
self.delegate = providers.SingletonDelegate(self.delegated)
|
||||
|
||||
def test_is_delegate(self):
|
||||
self.assertIsInstance(self.delegate, providers.Delegate)
|
||||
|
||||
def test_init_with_not_singleton(self):
|
||||
self.assertRaises(errors.Error,
|
||||
providers.SingletonDelegate,
|
||||
providers.Object(object()))
|
||||
|
|
Loading…
Reference in New Issue
Block a user