From 6574ef018d20e817212378fd95396865dee08d6c Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 11 Oct 2024 15:53:17 +0200 Subject: [PATCH] hide inherited members if the base class is not part of the documentation --- CHANGELOG.md | 2 + pdoc/render.py | 2 +- pdoc/templates/default/module.html.jinja2 | 4 + test/testdata/demo_long.html | 10 --- test/testdata/demopackage.html | 9 -- test/testdata/demopackage_dir.html | 18 ---- test/testdata/enums.html | 104 ---------------------- test/testdata/example_customtemplate.html | 9 -- test/testdata/flavors_google.html | 9 -- test/testdata/flavors_numpy.html | 9 -- test/testdata/misc.html | 26 ------ test/testdata/misc_py312.html | 10 --- test/testdata/misc_py313.html | 34 ------- test/testdata/top_level_reimports.html | 9 -- test/testdata/typed_dict.html | 47 ---------- 15 files changed, 7 insertions(+), 295 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 408abbde..ed90e041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - 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. ## 2024-09-11: pdoc 14.7.0 diff --git a/pdoc/render.py b/pdoc/render.py index c7f7410a..3fc524ea 100644 --- a/pdoc/render.py +++ b/pdoc/render.py @@ -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, diff --git a/pdoc/templates/default/module.html.jinja2 b/pdoc/templates/default/module.html.jinja2 index d1acf56e..9c4b0153 100644 --- a/pdoc/templates/default/module.html.jinja2 +++ b/pdoc/templates/default/module.html.jinja2 @@ -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 %} diff --git a/test/testdata/demo_long.html b/test/testdata/demo_long.html index 59cea137..ad4b73ea 100644 --- a/test/testdata/demo_long.html +++ b/test/testdata/demo_long.html @@ -1486,16 +1486,6 @@
Inherited Members
- -
-
Inherited Members
-
-
enum.Enum
-
name
-
value
- -
-
diff --git a/test/testdata/demopackage.html b/test/testdata/demopackage.html index d465c0ff..7c8c9905 100644 --- a/test/testdata/demopackage.html +++ b/test/testdata/demopackage.html @@ -381,15 +381,6 @@
Inherited Members
-
-
Inherited Members
-
-
G
-
g
- -
-
-
diff --git a/test/testdata/demopackage_dir.html b/test/testdata/demopackage_dir.html index 66e580f3..b5e63757 100644 --- a/test/testdata/demopackage_dir.html +++ b/test/testdata/demopackage_dir.html @@ -934,15 +934,6 @@
Inherited Members
-
-
Inherited Members
-
-
G
-
g
- -
-
-
@@ -1748,15 +1739,6 @@

-
-
Inherited Members
-
-
demopackage.subpackage.child_g.G
-
g
- -
-
-