diff --git a/README.rst b/README.rst index 6be9665..80e2313 100644 --- a/README.rst +++ b/README.rst @@ -87,8 +87,8 @@ and designed for Humans. * - .. code:: python + from typing import Annotated, List from injectable import Autowired, autowired - from typing import List from models import Database from messaging import Broker @@ -96,8 +96,8 @@ and designed for Humans. @autowired def __init__( self, - database: Autowired(Database), - message_brokers: Autowired(List[Broker]), + database: Annotated[Database, Autowired], + message_brokers: Annotated[List[Broker], Autowired], ): pending = database.get_pending_messages() for broker in message_brokers: @@ -149,7 +149,8 @@ Features you'll love ❤️ * **Qualifier overloading**: declare as many injectables as you like for a single qualifier or extending the same base class. You can inject all of them just by - specifying a :python:`typing.List` to :python:`Autowired`: :python:`deps: Autowired(List["qualifier"])`. + specifying a :python:`typing.List` to :python:`Autowired`: + :python:`deps: Annotated[List["qualifier"], Autowired]`. * **Transparent lazy initialization**: passing the argument :python:`lazy=True` for :python:`Autowired` will make your dependency to be initialized only when actually used, all @@ -160,7 +161,7 @@ Features you'll love ❤️ * **Namespaces**: specify different namespaces for injectables as in :python:`@injectable(namespace="foo")` and then just use them when annotating your - parameters as in :python:`dep: Autowired(..., namespace="foo")`. + parameters as in :python:`dep: Annotated[..., Autowired(namespace="foo")]`. * **Linters friendly**: :python:`Autowired` is carefully designed to comply with static linter analysis such as PyCharm's to preserve the parameter original type hint. diff --git a/docs/.buildinfo b/docs/.buildinfo index 48e29d4..c1e15aa 100644 --- a/docs/.buildinfo +++ b/docs/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 927fa4b8772f27b8ef95b7056f132ebc +config: c23d413b855c1456020e10f46639280c tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/_modules/index.html b/docs/_modules/index.html index 2a8b015..8911aa8 100644 --- a/docs/_modules/index.html +++ b/docs/_modules/index.html @@ -4,7 +4,7 @@
-
import inspect
from functools import wraps
-from typing import TypeVar, Callable, Any, get_args, _AnnotatedAlias, Union
+from typing import TypeVar, Callable, get_args, _AnnotatedAlias, Union
from injectable.autowiring.autowired_type import _Autowired, Autowired
from injectable.errors import AutowiringError
-T = TypeVar("T", bound=Callable[..., Any])
+R = TypeVar("R")
-[docs]def autowired(func: T) -> T:
+[docs]def autowired(func: Callable[..., R]) -> Callable[..., R]:
"""
Function decorator to setup dependency injection autowiring.
@@ -112,7 +112,7 @@ Source code for injectable.autowiring.autowired_decorator
raise AutowiringError("No parameter is typed with 'Autowired'")
@wraps(func)
- def wrapper(*args, **kwargs):
+ def wrapper(*args, **kwargs) -> R:
bound_arguments = signature.bind_partial(*args, **kwargs).arguments
args = list(args)
for parameter in autowired_parameters:
@@ -209,7 +209,7 @@ Navigation
diff --git a/docs/_sources/usage/namespaces.rst.txt b/docs/_sources/usage/namespaces.rst.txt
index 9b31091..220edd4 100644
--- a/docs/_sources/usage/namespaces.rst.txt
+++ b/docs/_sources/usage/namespaces.rst.txt
@@ -10,6 +10,9 @@ Namespaces Example
:caption: namespaces_example.py
:start-after: sphinx-start
+.. literalinclude:: ../../examples/namespaces/measuring_service_abc.py
+ :caption: measuring_service_abc.py
+
.. literalinclude:: ../../examples/namespaces/intl_measuring_service.py
:caption: intl_measuring_service.py
diff --git a/docs/_sources/usage/optional_injection.rst.txt b/docs/_sources/usage/optional_injection.rst.txt
index 67a5a95..506572d 100644
--- a/docs/_sources/usage/optional_injection.rst.txt
+++ b/docs/_sources/usage/optional_injection.rst.txt
@@ -9,3 +9,6 @@ Optional Injection Example
.. literalinclude:: ../../examples/optional_injection/optional_injection_example.py
:caption: optional_injection_example.py
:start-after: sphinx-start
+
+.. literalinclude:: ../../examples/optional_injection/service_xyz.py
+ :caption: service_xyz.py
diff --git a/docs/_static/documentation_options.js b/docs/_static/documentation_options.js
index 7440b26..d8e0e58 100644
--- a/docs/_static/documentation_options.js
+++ b/docs/_static/documentation_options.js
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
- VERSION: '4.0.0',
+ VERSION: '4.0.1',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
BUILDER: 'html',
diff --git a/docs/authors.html b/docs/authors.html
index 1b50a45..697c79b 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -5,7 +5,7 @@
- Authors — injectable 4.0.0 documentation
+ Authors — injectable 4.0.1 documentation
@@ -31,7 +31,7 @@
Navigation
-
@@ -119,7 +119,7 @@ Navigation