Skip to content

Commit

Permalink
hide inherited members if the base class is not part of the documenta…
Browse files Browse the repository at this point in the history
…tion (#748)
  • Loading branch information
mhils authored Oct 11, 2024
1 parent 98989b4 commit 72c0d51
Show file tree
Hide file tree
Showing 15 changed files with 8 additions and 295 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- Remove support for Python 3.8, which has reached end-of-life on 2024-10-07 .
([#747](https://github.com/mitmproxy/pdoc/pull/747), @mhils)
- Inherited members are now hidden by default if the base class is not part of the documentation.
Please make yourself heard in https://github.com/mitmproxy/pdoc/issues/715 if you relied on the old behavior.
([#748](https://github.com/mitmproxy/pdoc/pull/748), @mhils)

## 2024-09-11: pdoc 14.7.0

Expand Down
2 changes: 1 addition & 1 deletion pdoc/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def repr_module(module: pdoc.doc.Module) -> str:

env = Environment(
loader=FileSystemLoader(_default_searchpath),
extensions=[DefaultMacroExtension],
extensions=["jinja2.ext.loopcontrols", DefaultMacroExtension],
autoescape=True,
trim_blocks=True,
lstrip_blocks=True,
Expand Down
4 changes: 4 additions & 0 deletions pdoc/templates/default/module.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an
{# fmt: off #}
{% defaultmacro inherited(cls) %}
{% for base, members in cls.inherited_members.items() %}
{% if base[0] not in all_modules %}
{# hide inherited members from modules that are not in the documentation, https://github.com/mitmproxy/pdoc/issues/715 #}
{% continue %}
{% endif %}
{% set m = None %}{# workaround for https://github.com/pallets/jinja/issues/1427 #}
{% set member_html %}
{% for m in members if is_public(m) | trim %}
Expand Down
10 changes: 0 additions & 10 deletions test/testdata/demo_long.html
Original file line number Diff line number Diff line change
Expand Up @@ -1486,16 +1486,6 @@ <h5>Inherited Members</h5>



</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>enum.Enum</dt>
<dd id="EnumDemo.name" class="variable">name</dd>
<dd id="EnumDemo.value" class="variable">value</dd>

</div>
</dl>
</div>
</section>
<section id="embed_image">
Expand Down
9 changes: 0 additions & 9 deletions test/testdata/demopackage.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,6 @@ <h5>Inherited Members</h5>
</div>


<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt><a href="#G">G</a></dt>
<dd id="F.G.g" class="function"><a href="#G.g">g</a></dd>

</div>
</dl>
</div>
</section>
<section id="G">
<input id="G-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
Expand Down
18 changes: 0 additions & 18 deletions test/testdata/demopackage_dir.html
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,6 @@ <h5>Inherited Members</h5>
</div>
<div class=&quot;inherited&quot;>
<h5>Inherited Members</h5>
<dl>
<div><dt><a href=&quot;#G&quot;>G</a></dt>
<dd id=&quot;F.G.g&quot; class=&quot;function&quot;><a href=&quot;#G.g&quot;>g</a></dd>
</div>
</dl>
</div>
</section>
<section id=&quot;G&quot;>
<input id=&quot;G-view-source&quot; class=&quot;view-source-toggle-state&quot; type=&quot;checkbox&quot; aria-hidden=&quot;true&quot; tabindex=&quot;-1&quot;>
Expand Down Expand Up @@ -1748,15 +1739,6 @@ <h1 class=&quot;modulename&quot;>
</div>
<div class=&quot;inherited&quot;>
<h5>Inherited Members</h5>
<dl>
<div><dt>demopackage.subpackage.child_g.G</dt>
<dd id=&quot;F.G.g&quot; class=&quot;function&quot;>g</dd>
</div>
</dl>
</div>
</section>
</main>
<script>
Expand Down
104 changes: 0 additions & 104 deletions test/testdata/enums.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,6 @@ <h1 class="modulename">



</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>enum.Enum</dt>
<dd id="EnumDemo.name" class="variable">name</dd>
<dd id="EnumDemo.value" class="variable">value</dd>

</div>
</dl>
</div>
</section>
<section id="EnumWithoutDocstrings">
Expand Down Expand Up @@ -254,16 +244,6 @@ <h5>Inherited Members</h5>



</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>enum.Enum</dt>
<dd id="EnumWithoutDocstrings.name" class="variable">name</dd>
<dd id="EnumWithoutDocstrings.value" class="variable">value</dd>

</div>
</dl>
</div>
</section>
<section id="IntEnum">
Expand Down Expand Up @@ -308,30 +288,6 @@ <h5>Inherited Members</h5>



</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>enum.Enum</dt>
<dd id="IntEnum.name" class="variable">name</dd>
<dd id="IntEnum.value" class="variable">value</dd>

</div>
<div><dt>builtins.int</dt>
<dd id="IntEnum.conjugate" class="function">conjugate</dd>
<dd id="IntEnum.bit_length" class="function">bit_length</dd>
<dd id="IntEnum.bit_count" class="function">bit_count</dd>
<dd id="IntEnum.to_bytes" class="function">to_bytes</dd>
<dd id="IntEnum.from_bytes" class="function">from_bytes</dd>
<dd id="IntEnum.as_integer_ratio" class="function">as_integer_ratio</dd>
<dd id="IntEnum.is_integer" class="function">is_integer</dd>
<dd id="IntEnum.real" class="variable">real</dd>
<dd id="IntEnum.imag" class="variable">imag</dd>
<dd id="IntEnum.numerator" class="variable">numerator</dd>
<dd id="IntEnum.denominator" class="variable">denominator</dd>

</div>
</dl>
</div>
</section>
<section id="StrEnum">
Expand Down Expand Up @@ -376,66 +332,6 @@ <h5>Inherited Members</h5>



</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>enum.Enum</dt>
<dd id="StrEnum.name" class="variable">name</dd>
<dd id="StrEnum.value" class="variable">value</dd>

</div>
<div><dt>builtins.str</dt>
<dd id="StrEnum.encode" class="function">encode</dd>
<dd id="StrEnum.replace" class="function">replace</dd>
<dd id="StrEnum.split" class="function">split</dd>
<dd id="StrEnum.rsplit" class="function">rsplit</dd>
<dd id="StrEnum.join" class="function">join</dd>
<dd id="StrEnum.capitalize" class="function">capitalize</dd>
<dd id="StrEnum.casefold" class="function">casefold</dd>
<dd id="StrEnum.title" class="function">title</dd>
<dd id="StrEnum.center" class="function">center</dd>
<dd id="StrEnum.count" class="function">count</dd>
<dd id="StrEnum.expandtabs" class="function">expandtabs</dd>
<dd id="StrEnum.find" class="function">find</dd>
<dd id="StrEnum.partition" class="function">partition</dd>
<dd id="StrEnum.index" class="function">index</dd>
<dd id="StrEnum.ljust" class="function">ljust</dd>
<dd id="StrEnum.lower" class="function">lower</dd>
<dd id="StrEnum.lstrip" class="function">lstrip</dd>
<dd id="StrEnum.rfind" class="function">rfind</dd>
<dd id="StrEnum.rindex" class="function">rindex</dd>
<dd id="StrEnum.rjust" class="function">rjust</dd>
<dd id="StrEnum.rstrip" class="function">rstrip</dd>
<dd id="StrEnum.rpartition" class="function">rpartition</dd>
<dd id="StrEnum.splitlines" class="function">splitlines</dd>
<dd id="StrEnum.strip" class="function">strip</dd>
<dd id="StrEnum.swapcase" class="function">swapcase</dd>
<dd id="StrEnum.translate" class="function">translate</dd>
<dd id="StrEnum.upper" class="function">upper</dd>
<dd id="StrEnum.startswith" class="function">startswith</dd>
<dd id="StrEnum.endswith" class="function">endswith</dd>
<dd id="StrEnum.removeprefix" class="function">removeprefix</dd>
<dd id="StrEnum.removesuffix" class="function">removesuffix</dd>
<dd id="StrEnum.isascii" class="function">isascii</dd>
<dd id="StrEnum.islower" class="function">islower</dd>
<dd id="StrEnum.isupper" class="function">isupper</dd>
<dd id="StrEnum.istitle" class="function">istitle</dd>
<dd id="StrEnum.isspace" class="function">isspace</dd>
<dd id="StrEnum.isdecimal" class="function">isdecimal</dd>
<dd id="StrEnum.isdigit" class="function">isdigit</dd>
<dd id="StrEnum.isnumeric" class="function">isnumeric</dd>
<dd id="StrEnum.isalpha" class="function">isalpha</dd>
<dd id="StrEnum.isalnum" class="function">isalnum</dd>
<dd id="StrEnum.isidentifier" class="function">isidentifier</dd>
<dd id="StrEnum.isprintable" class="function">isprintable</dd>
<dd id="StrEnum.zfill" class="function">zfill</dd>
<dd id="StrEnum.format" class="function">format</dd>
<dd id="StrEnum.format_map" class="function">format_map</dd>
<dd id="StrEnum.maketrans" class="function">maketrans</dd>

</div>
</dl>
</div>
</section>
</main>
Expand Down
9 changes: 0 additions & 9 deletions test/testdata/example_customtemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,6 @@ <h1 class="modulename">


</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>builtins.object</dt>
<dd id="Dog.__lt__" class="function">__lt__</dd>

</div>
</dl>
</div>
</section>
</main>
</body>
Expand Down
9 changes: 0 additions & 9 deletions test/testdata/flavors_google.html
Original file line number Diff line number Diff line change
Expand Up @@ -1127,15 +1127,6 @@ <h6 id="attributes">Attributes:</h6>


</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>builtins.BaseException</dt>
<dd id="ExampleError.args" class="variable">args</dd>

</div>
</dl>
</div>
</section>
<section id="ExampleClass">
<input id="ExampleClass-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
Expand Down
9 changes: 0 additions & 9 deletions test/testdata/flavors_numpy.html
Original file line number Diff line number Diff line change
Expand Up @@ -1160,15 +1160,6 @@ <h6 id="attributes">Attributes</h6>


</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>builtins.BaseException</dt>
<dd id="ExampleError.args" class="variable">args</dd>

</div>
</dl>
</div>
</section>
<section id="ExampleClass">
<input id="ExampleClass-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
Expand Down
26 changes: 0 additions & 26 deletions test/testdata/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2271,23 +2271,6 @@ <h6 id="heading-6">Heading 6</h6>
</div>


<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>sched.scheduler</dt>
<dd id="scheduler.__init__" class="function">scheduler</dd>
<dd id="scheduler.timefunc" class="variable">timefunc</dd>
<dd id="scheduler.delayfunc" class="variable">delayfunc</dd>
<dd id="scheduler.enterabs" class="function">enterabs</dd>
<dd id="scheduler.enter" class="function">enter</dd>
<dd id="scheduler.cancel" class="function">cancel</dd>
<dd id="scheduler.empty" class="function">empty</dd>
<dd id="scheduler.run" class="function">run</dd>
<dd id="scheduler.queue" class="variable">queue</dd>

</div>
</dl>
</div>
</section>
<section id="__init__">
<input id="__init__-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
Expand Down Expand Up @@ -2565,15 +2548,6 @@ <h6 id="parameters">Parameters</h6>
</div>


<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>_ctypes.Structure</dt>
<dd id="DataclassStructure.__init__" class="function">Structure</dd>

</div>
</dl>
</div>
</section>
</main>
</body>
Expand Down
10 changes: 0 additions & 10 deletions test/testdata/misc_py312.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,6 @@ <h1 class="modulename">


</div>
<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>builtins.tuple</dt>
<dd id="NamedTupleExample.index" class="function">index</dd>
<dd id="NamedTupleExample.count" class="function">count</dd>

</div>
</dl>
</div>
</section>
</main>
</body>
Expand Down
34 changes: 0 additions & 34 deletions test/testdata/misc_py313.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,6 @@ <h1 class="modulename">



<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>builtins.dict</dt>
<dd id="MyDict.get" class="function">get</dd>
<dd id="MyDict.setdefault" class="function">setdefault</dd>
<dd id="MyDict.pop" class="function">pop</dd>
<dd id="MyDict.popitem" class="function">popitem</dd>
<dd id="MyDict.keys" class="function">keys</dd>
<dd id="MyDict.items" class="function">items</dd>
<dd id="MyDict.values" class="function">values</dd>
<dd id="MyDict.update" class="function">update</dd>
<dd id="MyDict.fromkeys" class="function">fromkeys</dd>
<dd id="MyDict.clear" class="function">clear</dd>
<dd id="MyDict.copy" class="function">copy</dd>

</div>
</dl>
</div>
</section>
<section id="CustomException">
<input id="CustomException-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
Expand All @@ -124,21 +105,6 @@ <h5>Inherited Members</h5>
</div>


<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt>builtins.RuntimeError</dt>
<dd id="CustomException.__init__" class="function">RuntimeError</dd>

</div>
<div><dt>builtins.BaseException</dt>
<dd id="CustomException.with_traceback" class="function">with_traceback</dd>
<dd id="CustomException.add_note" class="function">add_note</dd>
<dd id="CustomException.args" class="variable">args</dd>

</div>
</dl>
</div>
</section>
</main>
</body>
Expand Down
9 changes: 0 additions & 9 deletions test/testdata/top_level_reimports.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,6 @@ <h1 class="modulename">



<div class="inherited">
<h5>Inherited Members</h5>
<dl>
<div><dt><a href="#Foo">Foo</a></dt>
<dd id="Bar.FooSub" class="class"><a href="#Foo.FooSub">FooSub</a></dd>

</div>
</dl>
</div>
</section>
<section id="baz">
<input id="baz-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
Expand Down
Loading

0 comments on commit 72c0d51

Please sign in to comment.