From 72c0d51d9a0157b51a50cbd49da64decf687c20d Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 11 Oct 2024 15:58:25 +0200 Subject: [PATCH] hide inherited members if the base class is not part of the documentation (#748) --- CHANGELOG.md | 3 + 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, 8 insertions(+), 295 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 408abbde..795a2e6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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
- -
-
-