Skip to content

Commit

Permalink
Improve the usage xp of Autowired combined with Annotated
Browse files Browse the repository at this point in the history
  • Loading branch information
roo-oliv committed Jul 9, 2024
1 parent 5df30f2 commit 0f704ab
Show file tree
Hide file tree
Showing 55 changed files with 1,141 additions and 591 deletions.
2 changes: 1 addition & 1 deletion docs/.buildinfo
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
26 changes: 13 additions & 13 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,43 @@
<title>Overview: module code &#8212; 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">&#9776;</a></li>
<li><a href="../index.html">injectable-4.0.0</a> &#187;</li>
<li><a href="../index.html">injectable-4.0.0</a> &#187;</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>
Expand All @@ -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>
Expand Down Expand Up @@ -108,8 +108,8 @@ <h3>Navigation</h3>

<div class="footer" role="contentinfo">
&#169; 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>
57 changes: 37 additions & 20 deletions docs/_modules/injectable/autowiring/autowired_decorator.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 &#8212; injectable 3.4.7 documentation</title>
<title>injectable.autowiring.autowired_decorator &#8212; 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">&#9776;</a></li>
<li><a href="../../../index.html">injectable-3.4.7</a> &#187;</li>
<li><a href="../../index.html" accesskey="U">Module code</a> &#187;</li>
<li><a href="../../../index.html">injectable-4.0.0</a> &#187;</li>
<li><a href="../../index.html" accesskey="U">Module code</a> &#187;</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">&quot;T&quot;</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>
Expand Down Expand Up @@ -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">-&gt;</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">-&gt;</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">&gt;</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">&quot;Multiple Autowired annotations found&quot;</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">-&gt;</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>
Expand All @@ -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>
Expand Down Expand Up @@ -192,8 +209,8 @@ <h3>Navigation</h3>

<div class="footer" role="contentinfo">
&#169; 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>
Loading

0 comments on commit 0f704ab

Please sign in to comment.