Merge branch 'release/4.36.1' into master

This commit is contained in:
Roman Mogylatov 2021-09-28 14:51:54 -04:00
commit cf039a0c2b
9 changed files with 53 additions and 16 deletions

View File

@ -52,8 +52,8 @@ master_doc = 'index'
# General information about the project.
project = u'Dependency Injector'
copyright = u'2021, ETS Labs'
author = u'ETS Labs'
copyright = u'2021, Roman Mogylatov'
author = u'Roman Mogylatov'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@ -232,7 +232,7 @@ latex_elements = {
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'dependency_injector.tex', u'Dependency Injector Documentation',
u'ETS Labs', 'manual'),
u'Roman Mogylatov', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@ -303,7 +303,7 @@ html_theme_options = {
'github_button': True,
'github_banner': True,
'logo': 'logo.svg',
'description': 'Dependency injection framework for Python',
'description': 'Dependency injection framework for Python by Roman Mogylatov',
'code_font_size': '10pt',
'analytics_id': 'UA-67012059-1',
}

View File

@ -8,7 +8,7 @@ Boto3 example
:description: This example demonstrates a usage of Boto3 AWS client and Dependency Injector.
This example shows how to use ``Dependency Injector`` with `Boto3 <https://www.djangoproject.com/>`_.
This example shows how to use ``Dependency Injector`` with `Boto3 <https://github.com/boto/boto3>`_.
The source code is available on the `Github <https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/boto3-session>`_.

View File

@ -7,6 +7,17 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_
4.36.1
------
- Fix a wiring bug with improper resolving of ``Provide[some_provider.provider]``.
- Fix a typo in ``Factory`` provider docs ``service.add_attributes(clent=client)``
`#499 <https://github.com/ets-labs/python-dependency-injector/issues/499>`_.
Thanks to `@rajanjha786 <https://github.com/rajanjha786>`_ for the contribution.
- Fix a typo in ``boto3`` example
`#511 <https://github.com/ets-labs/python-dependency-injector/issues/511>`_.
Thanks to `@whysage <https://github.com/whysage>`_ for the contribution.
4.36.0
------
- Add support of non-string keys for ``FactoryAggregate`` provider.

View File

@ -39,19 +39,29 @@ a function or method argument:
Specifying an annotation is optional.
There are two types of markers:
- ``Provide[foo]`` - call the provider ``foo`` and injects the result
- ``Provider[foo]`` - injects the provider ``foo`` itself
To inject the provider itself use ``Provide[foo.provider]``:
.. code-block:: python
from dependency_injector.providers import Factory
from dependency_injector.wiring import inject, Provide
@inject
def foo(bar_provider: Factory[Bar] = Provide[Container.bar.provider]):
bar = bar_provider(argument="baz")
...
You can also use ``Provider[foo]`` for injecting the provider itself:
.. code-block:: python
from dependency_injector.providers import Factory
from dependency_injector.wiring import inject, Provider
@inject
def foo(bar_provider: Callable[..., Bar] = Provider[Container.bar]):
bar = bar_provider()
def foo(bar_provider: Factory[Bar] = Provider[Container.bar]):
bar = bar_provider(argument="baz")
...
You can use configuration, provided instance and sub-container providers as you normally do.

View File

@ -17,7 +17,7 @@ class Container(containers.DeclarativeContainer):
client = providers.Factory(Client)
service = providers.Factory(Service)
service.add_attributes(clent=client)
service.add_attributes(client=client)
if __name__ == '__main__':

View File

@ -1,6 +1,6 @@
"""Top-level package."""
__version__ = '4.36.0'
__version__ = '4.36.1'
"""Version number.
:type: str

View File

@ -226,7 +226,10 @@ class ProvidersMap:
self,
original: providers.Delegate,
) -> Optional[providers.Provider]:
return self._resolve_provider(original.provides)
provider = self._resolve_provider(original.provides)
if provider:
provider = provider.provider
return provider
def _resolve_config_option(
self,
@ -539,7 +542,10 @@ def _bind_injections(fn: Callable[..., Any], providers_map: ProvidersMap) -> Non
if isinstance(marker, Provide):
fn.__injections__[injection] = provider
elif isinstance(marker, Provider):
fn.__injections__[injection] = provider.provider
if isinstance(provider, providers.Delegate):
fn.__injections__[injection] = provider
else:
fn.__injections__[injection] = provider.provider
if injection in fn.__reference_closing__:
fn.__closing__[injection] = provider

View File

@ -84,7 +84,13 @@ def test_config_value_required_undefined(
@inject
def test_provide_provider(service_provider: Callable[..., Service] = Provider[Container.service.provider]):
def test_provide_provider(service_provider: Callable[..., Service] = Provide[Container.service.provider]):
service = service_provider()
return service
@inject
def test_provider_provider(service_provider: Callable[..., Service] = Provider[Container.service.provider]):
service = service_provider()
return service

View File

@ -169,6 +169,10 @@ class WiringTest(unittest.TestCase):
service = module.test_provide_provider()
self.assertIsInstance(service, Service)
def test_provider_provider(self):
service = module.test_provider_provider()
self.assertIsInstance(service, Service)
def test_provided_instance(self):
class TestService:
foo = {