Skip to content

Commit

Permalink
deploy: 595690e
Browse files Browse the repository at this point in the history
  • Loading branch information
wesselb committed Jun 28, 2024
1 parent d62ca63 commit f25500a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 4 additions & 2 deletions _modules/plum/repr.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ <h1>Source code for plum.repr</h1><div class="highlight"><pre>
<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">import</span> <span class="nn">typing</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">partial</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Iterable</span><span class="p">,</span> <span class="n">Optional</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Iterable</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Type</span><span class="p">,</span> <span class="n">TypeVar</span>

<span class="kn">import</span> <span class="nn">rich</span>
<span class="kn">from</span> <span class="nn">rich.color</span> <span class="kn">import</span> <span class="n">Color</span>
Expand All @@ -357,6 +357,8 @@ <h1>Source code for plum.repr</h1><div class="highlight"><pre>
<span class="s2">&quot;rich_repr&quot;</span><span class="p">,</span>
<span class="p">]</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">path_style</span> <span class="o">=</span> <span class="n">Style</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="n">Color</span><span class="o">.</span><span class="n">from_ansi</span><span class="p">(</span><span class="mi">7</span><span class="p">))</span>
<span class="n">file_style</span> <span class="o">=</span> <span class="n">Style</span><span class="p">(</span><span class="n">bold</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">underline</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

Expand Down Expand Up @@ -540,7 +542,7 @@ <h1>Source code for plum.repr</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">data</span>


<div class="viewcode-block" id="rich_repr"><a class="viewcode-back" href="../../api.html#plum.repr.rich_repr">[docs]</a><span class="k">def</span> <span class="nf">rich_repr</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">type</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="nb">str</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">):</span>
<div class="viewcode-block" id="rich_repr"><a class="viewcode-back" href="../../api.html#plum.repr.rich_repr">[docs]</a><span class="k">def</span> <span class="nf">rich_repr</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="nb">str</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Class decorator defining a `__repr__` method that calls :mod:`rich.`</span>

<span class="sd"> This also sets `_repr_mimebundle_` for better rendering in Jupyter.</span>
Expand Down
32 changes: 15 additions & 17 deletions _modules/plum/signature.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ <h1></h1>
<h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">inspect</span>
<span class="kn">import</span> <span class="nn">operator</span>
<span class="kn">import</span> <span class="nn">typing</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">copy</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Set</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">Union</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">ClassVar</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Set</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">Union</span>

<span class="kn">from</span> <span class="nn">rich.segment</span> <span class="kn">import</span> <span class="n">Segment</span>
<span class="kn">from</span> <span class="nn">typing_extensions</span> <span class="kn">import</span> <span class="n">Self</span>

<span class="kn">import</span> <span class="nn">beartype.door</span>
<span class="kn">from</span> <span class="nn">beartype.peps</span> <span class="kn">import</span> <span class="n">resolve_pep563</span> <span class="k">as</span> <span class="n">beartype_resolve_pep563</span>
Expand Down Expand Up @@ -379,17 +379,17 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span class="sd"> is_faithful (bool): Whether this signature only uses faithful types.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">_default_varargs</span> <span class="o">=</span> <span class="n">Missing</span>
<span class="n">_default_precedence</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">_default_varargs</span><span class="p">:</span> <span class="n">ClassVar</span> <span class="o">=</span> <span class="n">Missing</span>
<span class="n">_default_precedence</span><span class="p">:</span> <span class="n">ClassVar</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

<span class="vm">__slots__</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;types&quot;</span><span class="p">,</span> <span class="s2">&quot;varargs&quot;</span><span class="p">,</span> <span class="s2">&quot;precedence&quot;</span><span class="p">,</span> <span class="s2">&quot;is_faithful&quot;</span><span class="p">)</span>
<span class="vm">__slots__</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">...</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;types&quot;</span><span class="p">,</span> <span class="s2">&quot;varargs&quot;</span><span class="p">,</span> <span class="s2">&quot;precedence&quot;</span><span class="p">,</span> <span class="s2">&quot;is_faithful&quot;</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="o">*</span><span class="n">types</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="n">TypeHint</span><span class="p">,</span> <span class="o">...</span><span class="p">],</span>
<span class="n">varargs</span><span class="p">:</span> <span class="n">OptionalType</span> <span class="o">=</span> <span class="n">_default_varargs</span><span class="p">,</span>
<span class="n">precedence</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="n">_default_precedence</span><span class="p">,</span>
<span class="p">):</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Instantiate a signature, which contains exactly the information necessary for</span>
<span class="sd"> dispatch.</span>

Expand Down Expand Up @@ -428,17 +428,15 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span class="k">def</span> <span class="nf">has_varargs</span><span class="p">(</span><span class="bp">self</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="bp">self</span><span class="o">.</span><span class="n">varargs</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">Missing</span>

<span class="k">def</span> <span class="nf">__copy__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__copy__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Self</span><span class="p">:</span>
<span class="bp">cls</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="n">copy</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>
<span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__slots__</span><span class="p">:</span>
<span class="nb">setattr</span><span class="p">(</span><span class="n">copy</span><span class="p">,</span> <span class="n">attr</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">))</span>

<span class="n">copy</span><span class="o">.</span><span class="n">types</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span>
<span class="n">copy</span><span class="o">.</span><span class="n">varargs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">varargs</span>
<span class="n">copy</span><span class="o">.</span><span class="n">precedence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">precedence</span>
<span class="n">copy</span><span class="o">.</span><span class="n">is_faithful</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_faithful</span>
<span class="k">return</span> <span class="n">copy</span>

<span class="k">def</span> <span class="nf">__rich_console__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">console</span><span class="p">,</span> <span class="n">options</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__rich_console__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">console</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Segment</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">Segment</span><span class="p">(</span><span class="s2">&quot;Signature(&quot;</span><span class="p">)</span>
<span class="n">show_comma</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">:</span>
Expand All @@ -453,7 +451,7 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span class="k">yield</span> <span class="n">Segment</span><span class="p">(</span><span class="s2">&quot;precedence=&quot;</span> <span class="o">+</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">precedence</span><span class="p">))</span>
<span class="k">yield</span> <span class="n">Segment</span><span class="p">(</span><span class="s2">&quot;)&quot;</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">other</span><span class="p">,</span> <span class="n">Signature</span><span class="p">):</span>
<span class="k">return</span> <span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">,</span>
Expand Down Expand Up @@ -486,7 +484,7 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span></div>

<span class="k">def</span> <span class="fm">__le__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="k">def</span> <span class="fm">__le__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">:</span> <span class="s2">&quot;Signature&quot;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="c1"># If the number of types of the signatures are unequal, then the signature</span>
<span class="c1"># with the fewer number of types must be expanded using variable arguments.</span>
<span class="k">if</span> <span class="ow">not</span> <span class="p">(</span>
Expand Down Expand Up @@ -564,7 +562,7 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">False</span>

<div class="viewcode-block" id="Signature.match"><a class="viewcode-back" href="../../api.html#plum.signature.Signature.match">[docs]</a> <span class="k">def</span> <span class="nf">match</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<div class="viewcode-block" id="Signature.match"><a class="viewcode-back" href="../../api.html#plum.signature.Signature.match">[docs]</a> <span class="k">def</span> <span class="nf">match</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Check whether values match the signature.</span>

<span class="sd"> Args:</span>
Expand Down Expand Up @@ -636,7 +634,7 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">mismatches</span><span class="p">,</span> <span class="n">varargs_matched</span></div></div>


<span class="k">def</span> <span class="nf">inspect_signature</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">inspect</span><span class="o">.</span><span class="n">Signature</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">inspect_signature</span><span class="p">(</span><span class="n">f</span><span class="p">:</span> <span class="n">Callable</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">inspect</span><span class="o">.</span><span class="n">Signature</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Wrapper of :func:`inspect.signature` which adds support for certain non-function</span>
<span class="sd"> objects.</span>

Expand Down Expand Up @@ -690,7 +688,7 @@ <h1>Source code for plum.signature</h1><div class="highlight"><pre>

<span class="c1"># Parse and resolve annotation.</span>
<span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">annotation</span> <span class="ow">is</span> <span class="n">inspect</span><span class="o">.</span><span class="n">Parameter</span><span class="o">.</span><span class="n">empty</span><span class="p">:</span>
<span class="n">annotation</span> <span class="o">=</span> <span class="n">typing</span><span class="o">.</span><span class="n">Any</span>
<span class="n">annotation</span> <span class="o">=</span> <span class="n">Any</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">annotation</span> <span class="o">=</span> <span class="n">resolve_type_hint</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">annotation</span><span class="p">)</span>

Expand Down
Loading

0 comments on commit f25500a

Please sign in to comment.