mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-21 17:16:46 +03:00
Merge branch 'release/4.29.1' into master
This commit is contained in:
commit
6b57ce9f15
3
docs/_static/sphinx_rtd_theme-hotfix.css
vendored
3
docs/_static/sphinx_rtd_theme-hotfix.css
vendored
|
@ -1,3 +0,0 @@
|
|||
.rst-content .highlight>pre, .rst-content .linenodiv>pre {
|
||||
line-height: normal;
|
||||
}
|
|
@ -7,6 +7,14 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
4.29.1
|
||||
------
|
||||
- Fix recursive copying issue in ``Delegate`` provider.
|
||||
See issue: `#245 <https://github.com/ets-labs/python-dependency-injector/issues/245>`_.
|
||||
Thanks to `@GitterRemote <https://github.com/GitterRemote>`_ for reporting the issue.
|
||||
- Add docs and example for ``Factory.add_attributes()`` method.
|
||||
- Remove legacy css file.
|
||||
|
||||
4.29.0
|
||||
------
|
||||
- Implement context manager interface for resetting a singleton provider.
|
||||
|
|
|
@ -40,6 +40,14 @@ injected following these rules:
|
|||
:language: python
|
||||
:lines: 3-
|
||||
|
||||
``Factory`` provider can inject attributes. Use ``.add_attributes()`` method to specify
|
||||
attribute injections.
|
||||
|
||||
.. literalinclude:: ../../examples/providers/factory_attribute_injections.py
|
||||
:language: python
|
||||
:lines: 3-
|
||||
:emphasize-lines: 18-18
|
||||
|
||||
Passing arguments to the underlying providers
|
||||
---------------------------------------------
|
||||
|
||||
|
|
28
examples/providers/factory_attribute_injections.py
Normal file
28
examples/providers/factory_attribute_injections.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
"""`Factory` provider attribute injections example."""
|
||||
|
||||
from dependency_injector import containers, providers
|
||||
|
||||
|
||||
class Client:
|
||||
...
|
||||
|
||||
|
||||
class Service:
|
||||
def __init__(self) -> None:
|
||||
self.client = None
|
||||
|
||||
|
||||
class Container(containers.DeclarativeContainer):
|
||||
|
||||
client = providers.Factory(Client)
|
||||
|
||||
service = providers.Factory(Service)
|
||||
service.add_attributes(clent=client)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
container = Container()
|
||||
|
||||
service = container.service()
|
||||
|
||||
assert isinstance(service.client, Client)
|
|
@ -1,6 +1,6 @@
|
|||
"""Top-level package."""
|
||||
|
||||
__version__ = '4.29.0'
|
||||
__version__ = '4.29.1'
|
||||
"""Version number.
|
||||
|
||||
:type: str
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -91,9 +91,10 @@ class Self(Provider[T]):
|
|||
|
||||
|
||||
class Delegate(Provider[Provider]):
|
||||
def __init__(self, provides: Provider) -> None: ...
|
||||
def __init__(self, provides: Optional[Provider] = None) -> None: ...
|
||||
@property
|
||||
def provides(self) -> Provider: ...
|
||||
def provides(self) -> Optional[Provider]: ...
|
||||
def set_provides(self, provides: Optional[Provider]): ...
|
||||
|
||||
|
||||
class Dependency(Provider[T]):
|
||||
|
|
|
@ -519,13 +519,14 @@ cdef class Delegate(Provider):
|
|||
:type: object
|
||||
"""
|
||||
|
||||
def __init__(self, provides):
|
||||
def __init__(self, provides=None):
|
||||
"""Initializer.
|
||||
|
||||
:param provides: Value that have to be provided.
|
||||
:type provides: :py:class:`Provider`
|
||||
"""
|
||||
self.__provides = ensure_is_provider(provides)
|
||||
self.__provides = None
|
||||
self.set_provides(provides)
|
||||
super(Delegate, self).__init__()
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
|
@ -534,8 +535,11 @@ cdef class Delegate(Provider):
|
|||
if copied is not None:
|
||||
return copied
|
||||
|
||||
copied = self.__class__(deepcopy(self.__provides, memo))
|
||||
copied = self.__class__()
|
||||
memo[id(self)] = copied
|
||||
|
||||
if self.provides:
|
||||
copied.set_provides(deepcopy(self.provides, memo))
|
||||
self._copy_overridings(copied, memo)
|
||||
|
||||
return copied
|
||||
|
@ -556,9 +560,13 @@ cdef class Delegate(Provider):
|
|||
|
||||
@property
|
||||
def provides(self):
|
||||
"""Return provider."""
|
||||
return self.__provides
|
||||
|
||||
def set_provides(self, provides):
|
||||
if provides:
|
||||
provides = ensure_is_provider(provides)
|
||||
self.__provides = provides
|
||||
|
||||
@property
|
||||
def related(self):
|
||||
"""Return related providers generator."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user