-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the usage xp of Autowired combined with Annotated
- Loading branch information
Showing
55 changed files
with
1,141 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: 59603b7feaea2199af3a5ec748336286 | ||
config: 927fa4b8772f27b8ef95b7056f132ebc | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,43 +7,43 @@ | |
<title>Overview: module code — injectable 4.0.0 documentation</title> | ||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> | ||
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css" /> | ||
|
||
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> | ||
<script src="../_static/jquery.js"></script> | ||
<script src="../_static/underscore.js"></script> | ||
<script src="../_static/doctools.js"></script> | ||
|
||
<script src="../_static/sidebar.js"></script> | ||
|
||
<link rel="index" title="Index" href="../genindex.html" /> | ||
<link rel="search" title="Search" href="../search.html" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" /> | ||
<link rel="shortcut icon" type="image/png" href="../_static/favicon.png" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=0.8"> | ||
|
||
|
||
|
||
</head><body> | ||
<div class="related"> | ||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="responsive-menu"><a href="#sidebar-anchor" title="Navigation">☰</a></li> | ||
<li><a href="../index.html">injectable-4.0.0</a> »</li> | ||
<li><a href="../index.html">injectable-4.0.0</a> »</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="badge"> | ||
<a href="https://github.com/roo-oliv/injectable/">Fork me on GitHub</a> | ||
<img src="../_static/[email protected]"> | ||
</div> | ||
|
||
|
||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
<div class="body" role="main"> | ||
|
||
<h1>All modules for which code is available</h1> | ||
<ul><li><a href="injectable/autowiring/autowired_decorator.html">injectable.autowiring.autowired_decorator</a></li> | ||
<li><a href="injectable/autowiring/autowired_type.html">injectable.autowiring.autowired_type</a></li> | ||
|
@@ -67,7 +67,7 @@ <h1>All modules for which code is available</h1> | |
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
<a id="sidebar-anchor"></a> | ||
|
||
|
||
<div id="searchbox" style="display: none" role="search"> | ||
<h3 id="searchlabel">Quick search</h3> | ||
|
@@ -108,8 +108,8 @@ <h3>Navigation</h3> | |
|
||
<div class="footer" role="contentinfo"> | ||
© Copyright 2018, Rodrigo Martins de Oliveira. | ||
Last updated on Jul 04, 2024. | ||
Last updated on Jul 09, 2024. | ||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.5.0. | ||
</div> | ||
</body> | ||
</html> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,53 +4,53 @@ | |
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>injectable.autowiring.autowired_decorator — injectable 3.4.7 documentation</title> | ||
<title>injectable.autowiring.autowired_decorator — injectable 4.0.0 documentation</title> | ||
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" /> | ||
<link rel="stylesheet" type="text/css" href="../../../_static/pydoctheme.css" /> | ||
|
||
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script> | ||
<script src="../../../_static/jquery.js"></script> | ||
<script src="../../../_static/underscore.js"></script> | ||
<script src="../../../_static/doctools.js"></script> | ||
|
||
<script src="../../../_static/sidebar.js"></script> | ||
|
||
<link rel="index" title="Index" href="../../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../../search.html" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" /> | ||
<link rel="shortcut icon" type="image/png" href="../../../_static/favicon.png" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=0.8"> | ||
|
||
|
||
|
||
</head><body> | ||
<div class="related"> | ||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="responsive-menu"><a href="#sidebar-anchor" title="Navigation">☰</a></li> | ||
<li><a href="../../../index.html">injectable-3.4.7</a> »</li> | ||
<li><a href="../../index.html" accesskey="U">Module code</a> »</li> | ||
<li><a href="../../../index.html">injectable-4.0.0</a> »</li> | ||
<li><a href="../../index.html" accesskey="U">Module code</a> »</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="badge"> | ||
<a href="https://github.com/roo-oliv/injectable/">Fork me on GitHub</a> | ||
<img src="../../../_static/[email protected]"> | ||
</div> | ||
|
||
|
||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
<div class="body" role="main"> | ||
|
||
<h1>Source code for injectable.autowiring.autowired_decorator</h1><div class="highlight"><pre> | ||
<span></span><span class="kn">import</span> <span class="nn">inspect</span> | ||
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span> | ||
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">TypeVar</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Any</span><span class="p">,</span> <span class="n">get_args</span><span class="p">,</span> <span class="n">_AnnotatedAlias</span> | ||
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">TypeVar</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Any</span><span class="p">,</span> <span class="n">get_args</span><span class="p">,</span> <span class="n">_AnnotatedAlias</span><span class="p">,</span> <span class="n">Union</span> | ||
|
||
<span class="kn">from</span> <span class="nn">injectable.autowiring.autowired_type</span> <span class="kn">import</span> <span class="n">_Autowired</span> | ||
<span class="kn">from</span> <span class="nn">injectable.autowiring.autowired_type</span> <span class="kn">import</span> <span class="n">_Autowired</span><span class="p">,</span> <span class="n">Autowired</span> | ||
<span class="kn">from</span> <span class="nn">injectable.errors</span> <span class="kn">import</span> <span class="n">AutowiringError</span> | ||
|
||
<span class="n">T</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s2">"T"</span><span class="p">,</span> <span class="n">bound</span><span class="o">=</span><span class="n">Callable</span><span class="p">[</span><span class="o">...</span><span class="p">,</span> <span class="n">Any</span><span class="p">])</span> | ||
|
@@ -130,18 +130,35 @@ <h1>Source code for injectable.autowiring.autowired_decorator</h1><div class="hi | |
<span class="k">return</span> <span class="n">wrapper</span></div> | ||
|
||
|
||
<span class="k">def</span> <span class="nf">_get_parameter_annotation</span><span class="p">(</span><span class="n">parameter</span><span class="p">)</span> <span class="o">-></span> <span class="nb">type</span><span class="p">:</span> | ||
<span class="k">def</span> <span class="nf">_get_parameter_annotation</span><span class="p">(</span><span class="n">parameter</span><span class="p">)</span> <span class="o">-></span> <span class="n">Union</span><span class="p">[</span><span class="nb">type</span><span class="p">,</span> <span class="n">_Autowired</span><span class="p">]:</span> | ||
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span><span class="p">,</span> <span class="n">_AnnotatedAlias</span><span class="p">):</span> | ||
<span class="n">autowired_annotations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span> | ||
<span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">_Autowired</span><span class="p">),</span> <span class="n">get_args</span><span class="p">(</span><span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span><span class="p">))</span> | ||
<span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">_is_autowired</span><span class="p">(</span><span class="n">t</span><span class="p">),</span> <span class="n">get_args</span><span class="p">(</span><span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span><span class="p">))</span> | ||
<span class="p">)</span> | ||
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">autowired_annotations</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> | ||
<span class="k">return</span> <span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span> | ||
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">autowired_annotations</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span> | ||
<span class="k">raise</span> <span class="n">AutowiringError</span><span class="p">(</span><span class="s2">"Multiple Autowired annotations found"</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="n">autowired_annotations</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> | ||
<span class="n">autowired_annotation</span> <span class="o">=</span> <span class="n">autowired_annotations</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> | ||
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">autowired_annotation</span><span class="p">,</span> <span class="n">_Autowired</span><span class="p">):</span> | ||
<span class="k">return</span> <span class="n">autowired_annotation</span><span class="p">(</span><span class="n">dependency</span><span class="o">=</span><span class="n">get_args</span><span class="p">(</span><span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> | ||
<span class="k">if</span> <span class="n">autowired_annotation</span><span class="o">.</span><span class="n">dependency</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> | ||
<span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">autowired_annotation</span><span class="p">)(</span> | ||
<span class="n">dependency</span><span class="o">=</span><span class="n">get_args</span><span class="p">(</span><span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> | ||
<span class="n">namespace</span><span class="o">=</span><span class="n">autowired_annotation</span><span class="o">.</span><span class="n">namespace</span><span class="p">,</span> | ||
<span class="n">group</span><span class="o">=</span><span class="n">autowired_annotation</span><span class="o">.</span><span class="n">group</span><span class="p">,</span> | ||
<span class="n">exclude_groups</span><span class="o">=</span><span class="n">autowired_annotation</span><span class="o">.</span><span class="n">exclude_groups</span><span class="p">,</span> | ||
<span class="n">lazy</span><span class="o">=</span><span class="n">autowired_annotation</span><span class="o">.</span><span class="n">lazy</span><span class="p">,</span> | ||
<span class="p">)</span> | ||
<span class="k">return</span> <span class="n">autowired_annotation</span> | ||
|
||
<span class="k">return</span> <span class="n">parameter</span><span class="o">.</span><span class="n">annotation</span> | ||
|
||
|
||
<span class="k">def</span> <span class="nf">_is_autowired</span><span class="p">(</span><span class="n">annotation</span><span class="p">)</span> <span class="o">-></span> <span class="nb">bool</span><span class="p">:</span> | ||
<span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">annotation</span><span class="p">,</span> <span class="n">_Autowired</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span> | ||
<span class="n">inspect</span><span class="o">.</span><span class="n">isclass</span><span class="p">(</span><span class="n">annotation</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">annotation</span><span class="p">,</span> <span class="n">Autowired</span><span class="p">)</span> | ||
<span class="p">)</span> | ||
</pre></div> | ||
|
||
<div class="clearer"></div> | ||
|
@@ -151,7 +168,7 @@ <h1>Source code for injectable.autowiring.autowired_decorator</h1><div class="hi | |
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
<a id="sidebar-anchor"></a> | ||
|
||
|
||
<div id="searchbox" style="display: none" role="search"> | ||
<h3 id="searchlabel">Quick search</h3> | ||
|
@@ -192,8 +209,8 @@ <h3>Navigation</h3> | |
|
||
<div class="footer" role="contentinfo"> | ||
© Copyright 2018, Rodrigo Martins de Oliveira. | ||
Last updated on Jul 04, 2024. | ||
Last updated on Jul 09, 2024. | ||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.5.0. | ||
</div> | ||
</body> | ||
</html> | ||
</html> |
Oops, something went wrong.