diff --git a/CHANGELOG.md b/CHANGELOG.md index 9123845e..b2ee02ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Fix a CSS issue for overflowing math equations. ([#456](https://github.com/mitmproxy/pdoc/pull/456), @mhils) + - Fix a regression from poc 12.2: Enum members are now always documented + even if they do not have a docstring. ## 2022-11-05: pdoc 12.2.1 diff --git a/pdoc/doc.py b/pdoc/doc.py index 54174a94..13dd096e 100644 --- a/pdoc/doc.py +++ b/pdoc/doc.py @@ -1030,6 +1030,14 @@ def is_classvar(self) -> bool: else: return False + @cached_property + def is_enum_member(self) -> bool: + """`True` if the variable is an enum member, `False` otherwise.""" + if isinstance(self.default_value, enum.Enum): + return True + else: + return False + @cached_property def default_value_str(self) -> str: """The variable's default value as a pretty-printed str.""" diff --git a/pdoc/templates/default/module.html.jinja2 b/pdoc/templates/default/module.html.jinja2 index 059face7..7097d76a 100644 --- a/pdoc/templates/default/module.html.jinja2 +++ b/pdoc/templates/default/module.html.jinja2 @@ -237,7 +237,7 @@ See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an {% elif (doc.qualname or doc.name) is in(module.obj.__all__ or []) %} {# members starting with an underscore are still public if mentioned in __all__ #} true - {% elif not doc.name.startswith("_") and (doc.kind != "variable" or doc.docstring) %} + {% elif not doc.name.startswith("_") and (doc.kind != "variable" or doc.is_enum_member or doc.docstring) %} {# members not starting with an underscore are considered public by default #} true {% endif %} diff --git a/test/test_snapshot.py b/test/test_snapshot.py index 3ec082ad..7105dbd6 100755 --- a/test/test_snapshot.py +++ b/test/test_snapshot.py @@ -176,14 +176,14 @@ def test_snapshots(snapshot: Snapshot, format: str, monkeypatch): os.chdir(snapshot_dir) skipped_some = False for snapshot in snapshots: + if len(sys.argv) > 1 and snapshot.id not in sys.argv: + continue if sys.version_info < snapshot.min_version: print( f"Skipping {snapshot} as it requires a more recent version of Python." ) skipped_some = True continue - if len(sys.argv) > 1 and snapshot.id not in sys.argv: - continue for format in ["html", "repr"]: print(f"Rendering {snapshot} to {format}...") rendered = snapshot.make(format) diff --git a/test/testdata/demo_long.html b/test/testdata/demo_long.html index e86aae5c..1b4ba1d3 100644 --- a/test/testdata/demo_long.html +++ b/test/testdata/demo_long.html @@ -456,28 +456,27 @@
I am blue.
-250def admonitions(): -251 """ -252 pdoc also supports basic reStructuredText admonitions: -253 -254 ``` -255 .. note/warning/danger:: Optional title -256 Body text -257 ``` -258 -259 .. note:: -260 Hi there! -261 -262 .. warning:: Be Careful! -263 This warning has both a title and content. -264 -265 .. danger:: -266 Danger ahead. -267 -268 """ +diff --git a/test/testdata/demo_long.py b/test/testdata/demo_long.py index 9a8875b3..fa87f648 100644 --- a/test/testdata/demo_long.py +++ b/test/testdata/demo_long.py @@ -243,7 +243,6 @@ class EnumDemo(enum.Enum): GREEN = 2 """I am green.""" BLUE = enum.auto() - """I am blue.""" def admonitions(): diff --git a/test/testdata/demo_long.txt b/test/testdata/demo_long.txt index b38f550a..628d48b8 100644 --- a/test/testdata/demo_long.txt +++ b/test/testdata/demo_long.txt @@ -80,7 +80,7 @@ This …249def admonitions(): +250 """ +251 pdoc also supports basic reStructuredText admonitions: +252 +253 ``` +254 .. note/warning/danger:: Optional title +255 Body text +256 ``` +257 +258 .. note:: +259 Hi there! +260 +261 .. warning:: Be Careful! +262 This warning has both a title and content. +263 +264 .. danger:: +265 Danger ahead. +266 +267 """# I am the red.> # I am green.> - # I am blue.> + > > > \ No newline at end of file