From ff5b81fecb3eed950a469fe38d89ea2f09269b44 Mon Sep 17 00:00:00 2001 From: Rajan Jha Date: Mon, 13 Sep 2021 05:40:25 +0530 Subject: [PATCH 1/7] Fixed a typo in Factory provider docs "service.add_attributes(clent=client)" #499 (#504) --- examples/providers/factory_attribute_injections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/providers/factory_attribute_injections.py b/examples/providers/factory_attribute_injections.py index e9eaf528..f2d83e4b 100644 --- a/examples/providers/factory_attribute_injections.py +++ b/examples/providers/factory_attribute_injections.py @@ -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__': From cc4235257c03774b472020a0d954e34d6333a2b5 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sun, 12 Sep 2021 20:15:03 -0400 Subject: [PATCH 2/7] Update changelog --- docs/main/changelog.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index f59266fc..ffe04971 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,13 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ + +Develop +------- +- Fix a typo in ``Factory`` provider docs ``service.add_attributes(clent=client)`` + `#499 `_. + Thanks to `@rajanjha786 `_ for the contribution. + 4.36.0 ------ - Add support of non-string keys for ``FactoryAggregate`` provider. From 8377f2a82d44881be64dfe33eaaf3531bea500f3 Mon Sep 17 00:00:00 2001 From: whysage <67018871+whysage@users.noreply.github.com> Date: Thu, 16 Sep 2021 19:52:58 +0300 Subject: [PATCH 3/7] Fix boto3 url (#511) --- docs/examples/boto3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/boto3.rst b/docs/examples/boto3.rst index 8dc4bb6b..8ca76724 100644 --- a/docs/examples/boto3.rst +++ b/docs/examples/boto3.rst @@ -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 `_. +This example shows how to use ``Dependency Injector`` with `Boto3 `_. The source code is available on the `Github `_. From d8aa70c70b9071696e7ec4911ae70d95aa2bd616 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Thu, 16 Sep 2021 12:55:14 -0400 Subject: [PATCH 4/7] Update changelog.rst --- docs/main/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index ffe04971..6950db27 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -13,6 +13,9 @@ Develop - Fix a typo in ``Factory`` provider docs ``service.add_attributes(clent=client)`` `#499 `_. Thanks to `@rajanjha786 `_ for the contribution. +- Fix a typo in ``boto3`` example + `#511 `_. + Thanks to `@whysage `_ for the contribution. 4.36.0 ------ From 4733aad44eedc64a3111556397556acc6d89c09e Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sat, 25 Sep 2021 15:36:48 -0400 Subject: [PATCH 5/7] Fix provide issue (#514) --- docs/main/changelog.rst | 1 + docs/wiring.rst | 22 ++++++++++++++++------ src/dependency_injector/wiring.py | 10 ++++++++-- tests/unit/samples/wiringsamples/module.py | 8 +++++++- tests/unit/wiring/test_wiring_py36.py | 4 ++++ 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 6950db27..31ed445c 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -10,6 +10,7 @@ follows `Semantic versioning`_ Develop ------- +- 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 `_. Thanks to `@rajanjha786 `_ for the contribution. diff --git a/docs/wiring.rst b/docs/wiring.rst index ad74ad34..58deeae5 100644 --- a/docs/wiring.rst +++ b/docs/wiring.rst @@ -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. diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index 4dd77c09..a98c28c3 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -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 diff --git a/tests/unit/samples/wiringsamples/module.py b/tests/unit/samples/wiringsamples/module.py index 333de332..e1ccc112 100644 --- a/tests/unit/samples/wiringsamples/module.py +++ b/tests/unit/samples/wiringsamples/module.py @@ -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 diff --git a/tests/unit/wiring/test_wiring_py36.py b/tests/unit/wiring/test_wiring_py36.py index 7c503782..0d0a4a5f 100644 --- a/tests/unit/wiring/test_wiring_py36.py +++ b/tests/unit/wiring/test_wiring_py36.py @@ -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 = { From 5c7bdf4fc641b0ebd0dbc4697ef4861bda4bc028 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Tue, 28 Sep 2021 14:50:45 -0400 Subject: [PATCH 6/7] Update docs author --- docs/conf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a1260f49..58af81e8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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', } From 980914c2f73a532a2f2344197c524d55d50fdd11 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Tue, 28 Sep 2021 14:51:39 -0400 Subject: [PATCH 7/7] Bump version to 4.36.1 --- docs/main/changelog.rst | 4 ++-- src/dependency_injector/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 31ed445c..50bc7cae 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -8,8 +8,8 @@ From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ -Develop -------- +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 `_. diff --git a/src/dependency_injector/__init__.py b/src/dependency_injector/__init__.py index 7b9b9134..2c2b8ba3 100644 --- a/src/dependency_injector/__init__.py +++ b/src/dependency_injector/__init__.py @@ -1,6 +1,6 @@ """Top-level package.""" -__version__ = '4.36.0' +__version__ = '4.36.1' """Version number. :type: str