Skip to content

Commit

Permalink
deploy: b16bad1
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiyuanChen committed Aug 21, 2024
1 parent 4244868 commit 2457f87
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 100 deletions.
98 changes: 49 additions & 49 deletions configclass/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,8 @@ <h2 id="chanfig.configclasses.configclass" class="doc doc-heading">

<details class="quote">
<summary>Source code in <code>chanfig/configclasses.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">Python</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-25">25</a></span>
<div class="highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">Python</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-24">24</a></span>
<span class="normal"><a href="#__codelineno-0-25">25</a></span>
<span class="normal"><a href="#__codelineno-0-26">26</a></span>
<span class="normal"><a href="#__codelineno-0-27">27</a></span>
<span class="normal"><a href="#__codelineno-0-28">28</a></span>
Expand Down Expand Up @@ -1132,54 +1133,53 @@ <h2 id="chanfig.configclasses.configclass" class="doc doc-heading">
<span class="normal"><a href="#__codelineno-0-67">67</a></span>
<span class="normal"><a href="#__codelineno-0-68">68</a></span>
<span class="normal"><a href="#__codelineno-0-69">69</a></span>
<span class="normal"><a href="#__codelineno-0-70">70</a></span>
<span class="normal"><a href="#__codelineno-0-71">71</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-0-25" name="__codelineno-0-25"></a><span class="k">def</span> <span class="nf">configclass</span><span class="p">(</span><span class="bp">cls</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<a id="__codelineno-0-26" name="__codelineno-0-26"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<a id="__codelineno-0-27" name="__codelineno-0-27"></a><span class="sd"> Construct a Config in [`dataclass`][dataclasses.dataclass] style.</span>
<a id="__codelineno-0-28" name="__codelineno-0-28"></a>
<a id="__codelineno-0-29" name="__codelineno-0-29"></a><span class="sd"> This decorator creates a Config instance with the provided class attributes.</span>
<a id="__codelineno-0-30" name="__codelineno-0-30"></a>
<a id="__codelineno-0-31" name="__codelineno-0-31"></a><span class="sd"> See Also:</span>
<a id="__codelineno-0-32" name="__codelineno-0-32"></a><span class="sd"> [`dataclass`][dataclasses.dataclass]</span>
<a id="__codelineno-0-33" name="__codelineno-0-33"></a>
<a id="__codelineno-0-34" name="__codelineno-0-34"></a><span class="sd"> Args:</span>
<a id="__codelineno-0-35" name="__codelineno-0-35"></a><span class="sd"> cls (Type[Any]): The class to be enhanced, provided directly if no parentheses are used.</span>
<a id="__codelineno-0-36" name="__codelineno-0-36"></a>
<a id="__codelineno-0-37" name="__codelineno-0-37"></a><span class="sd"> Returns:</span>
<a id="__codelineno-0-38" name="__codelineno-0-38"></a><span class="sd"> A modified class with Config functionalities or a decorator with bound parameters.</span>
<a id="__codelineno-0-39" name="__codelineno-0-39"></a>
<a id="__codelineno-0-40" name="__codelineno-0-40"></a><span class="sd"> Examples:</span>
<a id="__codelineno-0-41" name="__codelineno-0-41"></a><span class="sd"> &gt;&gt;&gt; @configclass</span>
<a id="__codelineno-0-42" name="__codelineno-0-42"></a><span class="sd"> ... class DataloaderConfig:</span>
<a id="__codelineno-0-43" name="__codelineno-0-43"></a><span class="sd"> ... batch_size: int = 64</span>
<a id="__codelineno-0-44" name="__codelineno-0-44"></a><span class="sd"> ... num_workers: int = 4</span>
<a id="__codelineno-0-45" name="__codelineno-0-45"></a><span class="sd"> ... pin_memory: bool = True</span>
<a id="__codelineno-0-46" name="__codelineno-0-46"></a><span class="sd"> &gt;&gt;&gt; config = DataloaderConfig()</span>
<a id="__codelineno-0-47" name="__codelineno-0-47"></a><span class="sd"> &gt;&gt;&gt; print(config)</span>
<a id="__codelineno-0-48" name="__codelineno-0-48"></a><span class="sd"> DataloaderConfig(&lt;class &#39;chanfig.config.Config&#39;&gt;,</span>
<a id="__codelineno-0-49" name="__codelineno-0-49"></a><span class="sd"> (&#39;batch_size&#39;): 64</span>
<a id="__codelineno-0-50" name="__codelineno-0-50"></a><span class="sd"> (&#39;num_workers&#39;): 4</span>
<a id="__codelineno-0-51" name="__codelineno-0-51"></a><span class="sd"> (&#39;pin_memory&#39;): True</span>
<a id="__codelineno-0-52" name="__codelineno-0-52"></a><span class="sd"> )</span>
<a id="__codelineno-0-53" name="__codelineno-0-53"></a><span class="sd"> &quot;&quot;&quot;</span>
<a id="__codelineno-0-54" name="__codelineno-0-54"></a>
<a id="__codelineno-0-55" name="__codelineno-0-55"></a> <span class="n">warn</span><span class="p">(</span>
<a id="__codelineno-0-56" name="__codelineno-0-56"></a> <span class="s2">&quot;This decorator is deprecated and may be removed in the future release. &quot;</span>
<a id="__codelineno-0-57" name="__codelineno-0-57"></a> <span class="s2">&quot;All chanfig classes will copy variable identified in `__annotations__` by default.&quot;</span>
<a id="__codelineno-0-58" name="__codelineno-0-58"></a> <span class="s2">&quot;This decorator is equivalent to inheriting from `Config`.&quot;</span><span class="p">,</span>
<a id="__codelineno-0-59" name="__codelineno-0-59"></a> <span class="ne">PendingDeprecationWarning</span><span class="p">,</span>
<a id="__codelineno-0-60" name="__codelineno-0-60"></a> <span class="p">)</span>
<a id="__codelineno-0-61" name="__codelineno-0-61"></a>
<a id="__codelineno-0-62" name="__codelineno-0-62"></a> <span class="k">def</span> <span class="nf">decorator</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="n">Any</span><span class="p">]):</span>
<a id="__codelineno-0-63" name="__codelineno-0-63"></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">Config</span><span class="p">):</span>
<a id="__codelineno-0-64" name="__codelineno-0-64"></a> <span class="n">config_cls</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="p">(</span><span class="n">Config</span><span class="p">,</span> <span class="bp">cls</span><span class="p">),</span> <span class="nb">dict</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">))</span>
<a id="__codelineno-0-65" name="__codelineno-0-65"></a> <span class="bp">cls</span> <span class="o">=</span> <span class="n">config_cls</span>
<a id="__codelineno-0-66" name="__codelineno-0-66"></a>
<a id="__codelineno-0-67" name="__codelineno-0-67"></a> <span class="k">return</span> <span class="bp">cls</span>
<a id="__codelineno-0-68" name="__codelineno-0-68"></a>
<a id="__codelineno-0-69" name="__codelineno-0-69"></a> <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<a id="__codelineno-0-70" name="__codelineno-0-70"></a> <span class="k">return</span> <span class="n">decorator</span>
<a id="__codelineno-0-71" name="__codelineno-0-71"></a> <span class="k">return</span> <span class="n">decorator</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>
<span class="normal"><a href="#__codelineno-0-70">70</a></span></pre></div></td><td class="code"><div><pre><span></span><code><a id="__codelineno-0-24" name="__codelineno-0-24"></a><span class="k">def</span> <span class="nf">configclass</span><span class="p">(</span><span class="bp">cls</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<a id="__codelineno-0-25" name="__codelineno-0-25"></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<a id="__codelineno-0-26" name="__codelineno-0-26"></a><span class="sd"> Construct a Config in [`dataclass`][dataclasses.dataclass] style.</span>
<a id="__codelineno-0-27" name="__codelineno-0-27"></a>
<a id="__codelineno-0-28" name="__codelineno-0-28"></a><span class="sd"> This decorator creates a Config instance with the provided class attributes.</span>
<a id="__codelineno-0-29" name="__codelineno-0-29"></a>
<a id="__codelineno-0-30" name="__codelineno-0-30"></a><span class="sd"> See Also:</span>
<a id="__codelineno-0-31" name="__codelineno-0-31"></a><span class="sd"> [`dataclass`][dataclasses.dataclass]</span>
<a id="__codelineno-0-32" name="__codelineno-0-32"></a>
<a id="__codelineno-0-33" name="__codelineno-0-33"></a><span class="sd"> Args:</span>
<a id="__codelineno-0-34" name="__codelineno-0-34"></a><span class="sd"> cls (Type[Any]): The class to be enhanced, provided directly if no parentheses are used.</span>
<a id="__codelineno-0-35" name="__codelineno-0-35"></a>
<a id="__codelineno-0-36" name="__codelineno-0-36"></a><span class="sd"> Returns:</span>
<a id="__codelineno-0-37" name="__codelineno-0-37"></a><span class="sd"> A modified class with Config functionalities or a decorator with bound parameters.</span>
<a id="__codelineno-0-38" name="__codelineno-0-38"></a>
<a id="__codelineno-0-39" name="__codelineno-0-39"></a><span class="sd"> Examples:</span>
<a id="__codelineno-0-40" name="__codelineno-0-40"></a><span class="sd"> &gt;&gt;&gt; @configclass</span>
<a id="__codelineno-0-41" name="__codelineno-0-41"></a><span class="sd"> ... class DataloaderConfig:</span>
<a id="__codelineno-0-42" name="__codelineno-0-42"></a><span class="sd"> ... batch_size: int = 64</span>
<a id="__codelineno-0-43" name="__codelineno-0-43"></a><span class="sd"> ... num_workers: int = 4</span>
<a id="__codelineno-0-44" name="__codelineno-0-44"></a><span class="sd"> ... pin_memory: bool = True</span>
<a id="__codelineno-0-45" name="__codelineno-0-45"></a><span class="sd"> &gt;&gt;&gt; config = DataloaderConfig()</span>
<a id="__codelineno-0-46" name="__codelineno-0-46"></a><span class="sd"> &gt;&gt;&gt; print(config)</span>
<a id="__codelineno-0-47" name="__codelineno-0-47"></a><span class="sd"> DataloaderConfig(&lt;class &#39;chanfig.config.Config&#39;&gt;,</span>
<a id="__codelineno-0-48" name="__codelineno-0-48"></a><span class="sd"> (&#39;batch_size&#39;): 64</span>
<a id="__codelineno-0-49" name="__codelineno-0-49"></a><span class="sd"> (&#39;num_workers&#39;): 4</span>
<a id="__codelineno-0-50" name="__codelineno-0-50"></a><span class="sd"> (&#39;pin_memory&#39;): True</span>
<a id="__codelineno-0-51" name="__codelineno-0-51"></a><span class="sd"> )</span>
<a id="__codelineno-0-52" name="__codelineno-0-52"></a><span class="sd"> &quot;&quot;&quot;</span>
<a id="__codelineno-0-53" name="__codelineno-0-53"></a>
<a id="__codelineno-0-54" name="__codelineno-0-54"></a> <span class="n">warn</span><span class="p">(</span>
<a id="__codelineno-0-55" name="__codelineno-0-55"></a> <span class="s2">&quot;This decorator is deprecated and may be removed in the future release. &quot;</span>
<a id="__codelineno-0-56" name="__codelineno-0-56"></a> <span class="s2">&quot;All chanfig classes will copy variable identified in `__annotations__` by default.&quot;</span>
<a id="__codelineno-0-57" name="__codelineno-0-57"></a> <span class="s2">&quot;This decorator is equivalent to inheriting from `Config`.&quot;</span><span class="p">,</span>
<a id="__codelineno-0-58" name="__codelineno-0-58"></a> <span class="ne">PendingDeprecationWarning</span><span class="p">,</span>
<a id="__codelineno-0-59" name="__codelineno-0-59"></a> <span class="p">)</span>
<a id="__codelineno-0-60" name="__codelineno-0-60"></a>
<a id="__codelineno-0-61" name="__codelineno-0-61"></a> <span class="k">def</span> <span class="nf">decorator</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="n">Any</span><span class="p">]):</span>
<a id="__codelineno-0-62" name="__codelineno-0-62"></a> <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">Config</span><span class="p">):</span>
<a id="__codelineno-0-63" name="__codelineno-0-63"></a> <span class="n">config_cls</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="p">(</span><span class="n">Config</span><span class="p">,</span> <span class="bp">cls</span><span class="p">),</span> <span class="nb">dict</span><span class="p">(</span><span class="bp">cls</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">))</span>
<a id="__codelineno-0-64" name="__codelineno-0-64"></a> <span class="bp">cls</span> <span class="o">=</span> <span class="n">config_cls</span>
<a id="__codelineno-0-65" name="__codelineno-0-65"></a>
<a id="__codelineno-0-66" name="__codelineno-0-66"></a> <span class="k">return</span> <span class="bp">cls</span>
<a id="__codelineno-0-67" name="__codelineno-0-67"></a>
<a id="__codelineno-0-68" name="__codelineno-0-68"></a> <span class="k">if</span> <span class="bp">cls</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<a id="__codelineno-0-69" name="__codelineno-0-69"></a> <span class="k">return</span> <span class="n">decorator</span>
<a id="__codelineno-0-70" name="__codelineno-0-70"></a> <span class="k">return</span> <span class="n">decorator</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>
</code></pre></div></td></tr></table></div>
</details>
</div>
Expand Down
Loading

0 comments on commit 2457f87

Please sign in to comment.