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
    + +
    + +
    + + def + dynamically_modify_docstring1(): + + + +
    + +
    406def dynamically_modify_docstring1():
    +407    """this should **not** be the docstring."""
    +
    + + +

    https://github.com/mitmproxy/pdoc/issues/536

    +
    + + +
    +
    + +
    + + def + dynamically_modify_docstring2(): + + + +
    + +
    410def dynamically_modify_docstring2():
    +411    pass
    +
    + + +

    https://github.com/mitmproxy/pdoc/issues/536

    +
    + + +
    +
    + +
    + + def + dynamically_modify_docstring3(): + + + +
    + +
    423@_docstring_modifier
    +424def dynamically_modify_docstring3():
    +425    """This should **not** be the docstring."""
    +
    + + +

    https://github.com/mitmproxy/pdoc/issues/536

    +
    + + +
    +
    + +
    + + def + dynamically_modify_docstring4(): + + + +
    + +
    428@_docstring_modifier
    +429def dynamically_modify_docstring4():
    +430    pass
    +
    + + +

    https://github.com/mitmproxy/pdoc/issues/536

    +
    + +
    diff --git a/test/testdata/misc.py b/test/testdata/misc.py index 92174bb0..fc4ef7e8 100644 --- a/test/testdata/misc.py +++ b/test/testdata/misc.py @@ -402,6 +402,33 @@ class __init__: """https://github.com/mitmproxy/pdoc/issues/519""" +def dynamically_modify_docstring1(): + """this should **not** be the docstring.""" + + +def dynamically_modify_docstring2(): + pass + + +dynamically_modify_docstring1.__doc__ = "https://github.com/mitmproxy/pdoc/issues/536" +dynamically_modify_docstring2.__doc__ = "https://github.com/mitmproxy/pdoc/issues/536" + + +def _docstring_modifier(fn): + fn.__doc__ = "https://github.com/mitmproxy/pdoc/issues/536" + return fn + + +@_docstring_modifier +def dynamically_modify_docstring3(): + """This should **not** be the docstring.""" + + +@_docstring_modifier +def dynamically_modify_docstring4(): + pass + + __all__ = [ "Issue226", "var_with_default_obj", @@ -437,4 +464,8 @@ class __init__: "ClassAsAttribute", "scheduler", "__init__", + "dynamically_modify_docstring1", + "dynamically_modify_docstring2", + "dynamically_modify_docstring3", + "dynamically_modify_docstring4", ] diff --git a/test/testdata/misc.txt b/test/testdata/misc.txt index 85b53152..528464bf 100644 --- a/test/testdata/misc.txt +++ b/test/testdata/misc.txt @@ -117,4 +117,8 @@ > + + + <@_docstring_modifier function def dynamically_modify_docstring3(): ... # https://github.com/m…> + <@_docstring_modifier function def dynamically_modify_docstring4(): ... # https://github.com/m…> > \ No newline at end of file