diff --git a/CHANGELOG.md b/CHANGELOG.md
index faf7ffe2..b748e178 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
+ - Fix rendering of dynamically modified docstrings.
- `pdoc.doc_ast.AstInfo` now has separate `func_docstrings` and `var_docstrings` attributes
instead of one combined one.
diff --git a/pdoc/doc.py b/pdoc/doc.py
index b1721cef..b1bcef42 100644
--- a/pdoc/doc.py
+++ b/pdoc/doc.py
@@ -317,7 +317,7 @@ def members(self) -> dict[str, Doc]:
)
if self._var_docstrings.get(name):
doc.docstring = self._var_docstrings[name]
- if self._func_docstrings.get(name):
+ if self._func_docstrings.get(name) and not doc.docstring:
doc.docstring = self._func_docstrings[name]
members[doc.name] = doc
diff --git a/test/testdata/misc.html b/test/testdata/misc.html
index 29b439ae..51ed95c6 100644
--- a/test/testdata/misc.html
+++ b/test/testdata/misc.html
@@ -266,6 +266,18 @@
API Documentation
+
+ dynamically_modify_docstring1
+
+
+ dynamically_modify_docstring2
+
+
+ dynamically_modify_docstring3
+
+
+ dynamically_modify_docstring4
+
@@ -691,42 +703,73 @@
402 """https://github.com/mitmproxy/pdoc/issues/519"""
403
404
-405__all__ = [
-406 "Issue226",
-407 "var_with_default_obj",
-408 "var_with_default_func",
-409 "func_with_defaults",
-410 "ClassmethodLink",
-411 "GenericParent",
-412 "NonGenericChild",
-413 "Child",
-414 "only_annotated",
-415 "_Private",
-416 "LambdaAttr",
-417 "foo",
-418 "bar",
-419 "baz",
-420 "qux",
-421 "Indented",
-422 "fun_with_protected_decorator",
-423 "unhashable",
-424 "AbstractClass",
-425 "add_four",
-426 "add_five",
-427 "add_six",
-428 "linkify_links",
-429 "Issue352a",
-430 "Issue352b",
-431 "CustomCall",
-432 "Headings",
-433 "repr_not_syntax_highlightable",
-434 "ClassDecorator",
-435 "another_decorated_function",
-436 "SubclassRef",
-437 "ClassAsAttribute",
-438 "scheduler",
-439 "__init__",
-440]
+405def dynamically_modify_docstring1():
+406 """this should **not** be the docstring."""
+407
+408
+409def dynamically_modify_docstring2():
+410 pass
+411
+412
+413dynamically_modify_docstring1.__doc__ = "https://github.com/mitmproxy/pdoc/issues/536"
+414dynamically_modify_docstring2.__doc__ = "https://github.com/mitmproxy/pdoc/issues/536"
+415
+416
+417def _docstring_modifier(fn):
+418 fn.__doc__ = "https://github.com/mitmproxy/pdoc/issues/536"
+419 return fn
+420
+421
+422@_docstring_modifier
+423def dynamically_modify_docstring3():
+424 """This should **not** be the docstring."""
+425
+426
+427@_docstring_modifier
+428def dynamically_modify_docstring4():
+429 pass
+430
+431
+432__all__ = [
+433 "Issue226",
+434 "var_with_default_obj",
+435 "var_with_default_func",
+436 "func_with_defaults",
+437 "ClassmethodLink",
+438 "GenericParent",
+439 "NonGenericChild",
+440 "Child",
+441 "only_annotated",
+442 "_Private",
+443 "LambdaAttr",
+444 "foo",
+445 "bar",
+446 "baz",
+447 "qux",
+448 "Indented",
+449 "fun_with_protected_decorator",
+450 "unhashable",
+451 "AbstractClass",
+452 "add_four",
+453 "add_five",
+454 "add_six",
+455 "linkify_links",
+456 "Issue352a",
+457 "Issue352b",
+458 "CustomCall",
+459 "Headings",
+460 "repr_not_syntax_highlightable",
+461 "ClassDecorator",
+462 "another_decorated_function",
+463 "SubclassRef",
+464 "ClassAsAttribute",
+465 "scheduler",
+466 "__init__",
+467 "dynamically_modify_docstring1",
+468 "dynamically_modify_docstring2",
+469 "dynamically_modify_docstring3",
+470 "dynamically_modify_docstring4",
+471]
@@ -2212,6 +2255,92 @@ Inherited Members
+
+
+
+
+