Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Sep 2, 2024
1 parent dae19f2 commit 283b88d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Unreleased: pdoc next

- pdoc now strips `collections.abc.` from type annotations to make them more concise.
([#736](https://github.com/mitmproxy/pdoc/pull/736), @mhils)

## 2024-08-27: pdoc 14.6.1

Expand Down
1 change: 1 addition & 0 deletions pdoc/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ def _remove_memory_addresses(x: str) -> str:
"""Remove memory addresses from repr() output"""
return re.sub(r" at 0x[0-9a-fA-F]+(?=>)", "", x)


def _remove_collections_abc(x: str) -> str:
"""Remove 'collections.abc' from type signatures."""
return re.sub(r"(?!\.)\bcollections\.abc\.", "", x)
53 changes: 33 additions & 20 deletions test/testdata/collections_abc.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,26 @@ <h1 class="modulename">
<label class="view-source-button" for="mod-collections_abc-view-source"><span>View Source</span></label>

<div class="pdoc-code codehilite"><pre><span></span><span id="L-1"><a href="#L-1"><span class="linenos"> 1</span></a><span class="sd">&quot;&quot;&quot;Test that we remove &#39;collections.abc&#39; from type signatures.&quot;&quot;&quot;</span>
</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a><span class="kn">from</span> <span class="nn">collections.abc</span> <span class="kn">import</span> <span class="n">Awaitable</span><span class="p">,</span> <span class="n">Container</span>
</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a>
</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a>
</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a><span class="k">def</span> <span class="nf">func</span><span class="p">(</span>
</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a> <span class="n">bar</span><span class="p">:</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">]</span>
</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">]:</span>
</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a> <span class="k">return</span> <span class="n">bar</span>
</span><span id="L-2"><a href="#L-2"><span class="linenos"> 2</span></a>
</span><span id="L-3"><a href="#L-3"><span class="linenos"> 3</span></a><span class="kn">from</span> <span class="nn">collections.abc</span> <span class="kn">import</span> <span class="n">Awaitable</span>
</span><span id="L-4"><a href="#L-4"><span class="linenos"> 4</span></a><span class="kn">from</span> <span class="nn">collections.abc</span> <span class="kn">import</span> <span class="n">Container</span>
</span><span id="L-5"><a href="#L-5"><span class="linenos"> 5</span></a>
</span><span id="L-6"><a href="#L-6"><span class="linenos"> 6</span></a>
</span><span id="L-7"><a href="#L-7"><span class="linenos"> 7</span></a><span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">bar</span><span class="p">:</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">]:</span>
</span><span id="L-8"><a href="#L-8"><span class="linenos"> 8</span></a> <span class="k">return</span> <span class="n">bar</span>
</span><span id="L-9"><a href="#L-9"><span class="linenos"> 9</span></a>
</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a><span class="k">class</span> <span class="nc">Class</span><span class="p">(</span><span class="n">Container</span><span class="p">[</span><span class="nb">str</span><span class="p">]):</span>
</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a> <span class="k">return</span> <span class="n">item</span> <span class="o">==</span> <span class="s2">&quot;Bar&quot;</span>
</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a>
</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a><span class="n">var</span><span class="p">:</span> <span class="n">Container</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;baz&quot;</span>
</span><span id="L-10"><a href="#L-10"><span class="linenos">10</span></a>
</span><span id="L-11"><a href="#L-11"><span class="linenos">11</span></a><span class="k">class</span> <span class="nc">Class</span><span class="p">(</span><span class="n">Container</span><span class="p">[</span><span class="nb">str</span><span class="p">]):</span>
</span><span id="L-12"><a href="#L-12"><span class="linenos">12</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
</span><span id="L-13"><a href="#L-13"><span class="linenos">13</span></a><span class="sd"> For subclasses, we currently display the full classname.</span>
</span><span id="L-14"><a href="#L-14"><span class="linenos">14</span></a><span class="sd"> Mostly because it&#39;s easier, but it also makes a bit more sense here.</span>
</span><span id="L-15"><a href="#L-15"><span class="linenos">15</span></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="L-16"><a href="#L-16"><span class="linenos">16</span></a>
</span><span id="L-17"><a href="#L-17"><span class="linenos">17</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
</span><span id="L-18"><a href="#L-18"><span class="linenos">18</span></a> <span class="k">return</span> <span class="n">item</span> <span class="o">==</span> <span class="s2">&quot;Bar&quot;</span>
</span><span id="L-19"><a href="#L-19"><span class="linenos">19</span></a>
</span><span id="L-20"><a href="#L-20"><span class="linenos">20</span></a>
</span><span id="L-21"><a href="#L-21"><span class="linenos">21</span></a><span class="n">var</span><span class="p">:</span> <span class="n">Container</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;baz&quot;</span>
</span></pre></div>


Expand All @@ -87,10 +94,8 @@ <h1 class="modulename">

</div>
<a class="headerlink" href="#func"></a>
<div class="pdoc-code codehilite"><pre><span></span><span id="func-6"><a href="#func-6"><span class="linenos">6</span></a><span class="k">def</span> <span class="nf">func</span><span class="p">(</span>
</span><span id="func-7"><a href="#func-7"><span class="linenos">7</span></a> <span class="n">bar</span><span class="p">:</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">]</span>
</span><span id="func-8"><a href="#func-8"><span class="linenos">8</span></a><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">]:</span>
</span><span id="func-9"><a href="#func-9"><span class="linenos">9</span></a> <span class="k">return</span> <span class="n">bar</span>
<div class="pdoc-code codehilite"><pre><span></span><span id="func-8"><a href="#func-8"><span class="linenos">8</span></a><span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">bar</span><span class="p">:</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Awaitable</span><span class="p">[</span><span class="kc">None</span><span class="p">]:</span>
</span><span id="func-9"><a href="#func-9"><span class="linenos">9</span></a> <span class="k">return</span> <span class="n">bar</span>
</span></pre></div>


Expand All @@ -108,13 +113,21 @@ <h1 class="modulename">

</div>
<a class="headerlink" href="#Class"></a>
<div class="pdoc-code codehilite"><pre><span></span><span id="Class-11"><a href="#Class-11"><span class="linenos">11</span></a><span class="k">class</span> <span class="nc">Class</span><span class="p">(</span><span class="n">Container</span><span class="p">[</span><span class="nb">str</span><span class="p">]):</span>
</span><span id="Class-12"><a href="#Class-12"><span class="linenos">12</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
</span><span id="Class-13"><a href="#Class-13"><span class="linenos">13</span></a> <span class="k">return</span> <span class="n">item</span> <span class="o">==</span> <span class="s2">&quot;Bar&quot;</span>
<div class="pdoc-code codehilite"><pre><span></span><span id="Class-12"><a href="#Class-12"><span class="linenos">12</span></a><span class="k">class</span> <span class="nc">Class</span><span class="p">(</span><span class="n">Container</span><span class="p">[</span><span class="nb">str</span><span class="p">]):</span>
</span><span id="Class-13"><a href="#Class-13"><span class="linenos">13</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
</span><span id="Class-14"><a href="#Class-14"><span class="linenos">14</span></a><span class="sd"> For subclasses, we currently display the full classname.</span>
</span><span id="Class-15"><a href="#Class-15"><span class="linenos">15</span></a><span class="sd"> Mostly because it&#39;s easier, but it also makes a bit more sense here.</span>
</span><span id="Class-16"><a href="#Class-16"><span class="linenos">16</span></a><span class="sd"> &quot;&quot;&quot;</span>
</span><span id="Class-17"><a href="#Class-17"><span class="linenos">17</span></a>
</span><span id="Class-18"><a href="#Class-18"><span class="linenos">18</span></a> <span class="k">def</span> <span class="fm">__contains__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
</span><span id="Class-19"><a href="#Class-19"><span class="linenos">19</span></a> <span class="k">return</span> <span class="n">item</span> <span class="o">==</span> <span class="s2">&quot;Bar&quot;</span>
</span></pre></div>



<div class="docstring"><p>For subclasses, we currently display the full classname.
Mostly because it's easier, but it also makes a bit more sense here.</p>
</div>


</section>
<section id="var">
Expand Down
25 changes: 14 additions & 11 deletions test/testdata/collections_abc.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
"""Test that we remove 'collections.abc' from type signatures."""
from collections.abc import Awaitable, Container

from collections.abc import Awaitable
from collections.abc import Container


def func(bar: Awaitable[None]) -> Awaitable[None]:
return bar

def func(
bar: Awaitable[None]
) -> Awaitable[None]:
return bar

class Class(Container[str]):
"""
For subclasses, we currently display the full classname.
Mostly because it's easier, but it also makes a bit more sense here.
"""
def __contains__(self, item):
return item == "Bar"
"""
For subclasses, we currently display the full classname.
Mostly because it's easier, but it also makes a bit more sense here.
"""

def __contains__(self, item):
return item == "Bar"


var: Container[str] = "baz"
2 changes: 1 addition & 1 deletion test/testdata/collections_abc.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<module collections_abc # Test that we remove …
<function def func(bar: Awaitable[None]) -> Awaitable[None]: ...>
<class collections_abc.Class
<class collections_abc.Class # For subclasses, we c…
<method def __init__(): ...>
>
<var var: Container[str] = 'baz'>
Expand Down

0 comments on commit 283b88d

Please sign in to comment.