mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 03:36:41 +03:00
Add providers @override decorator
This commit is contained in:
parent
e46ffeb1bc
commit
a86df49160
|
@ -1037,3 +1037,32 @@ class ChildConfig(Provider):
|
|||
provides='.'.join(self.parents))
|
||||
|
||||
__repr__ = __str__
|
||||
|
||||
|
||||
def override(overridden):
|
||||
"""Decorator for overriding providers.
|
||||
|
||||
This decorator overrides ``overridden`` provider by decorated one.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@Factory
|
||||
class SomeClass(object):
|
||||
pass
|
||||
|
||||
|
||||
@override(SomeClass)
|
||||
@Factory
|
||||
class ExtendedSomeClass(SomeClass.cls):
|
||||
pass
|
||||
|
||||
:param overridden: Provider that should be overridden.
|
||||
:type overridden: :py:class:`Provider`
|
||||
|
||||
:return: Overriding provider.
|
||||
:rtype: :py:class:`Provider`
|
||||
"""
|
||||
def decorator(overriding):
|
||||
overridden.override(overriding)
|
||||
return overriding
|
||||
return decorator
|
||||
|
|
Loading…
Reference in New Issue
Block a user