Skip to content

Commit

Permalink
pick up docstrings from pyi files, fix #613
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Sep 6, 2023
1 parent b2cf646 commit 8b99723
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<!-- ✨ You do not need to add a pull request reference or an author, this will be added automatically by CI. ✨ -->

- pdoc now also picks up docstrings from `.pyi` stub files.
- Fix horizontal scroll navigation z-index issue.
([#616](https://github.com/mitmproxy/pdoc/pull/616), @Domi04151309)

Expand Down
3 changes: 3 additions & 0 deletions pdoc/doc_pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ def _patch_doc(target_doc: doc.Doc, stub_mod: doc.Module) -> None:
if isinstance(target_doc, doc.Function) and isinstance(stub_doc, doc.Function):
target_doc.signature = stub_doc.signature
target_doc.funcdef = stub_doc.funcdef
target_doc.docstring = stub_doc.docstring or target_doc.docstring
elif isinstance(target_doc, doc.Variable) and isinstance(stub_doc, doc.Variable):
target_doc.annotation = stub_doc.annotation
target_doc.docstring = stub_doc.docstring or target_doc.docstring
elif isinstance(target_doc, doc.Namespace) and isinstance(stub_doc, doc.Namespace):
target_doc.docstring = stub_doc.docstring or target_doc.docstring
for m in target_doc.members.values():
_patch_doc(m, stub_mod)
else:
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/type_stub.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h1 class="modulename">
</div>
<a class="headerlink" href="#var"></a>

<div class="docstring"><p>A simple variable.</p>
<div class="docstring"><p>Docstring override from the .pyi file.</p>
</div>


Expand Down
1 change: 1 addition & 0 deletions test/testdata/type_stub.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from typing import Iterable
def func(x: str, y: Any, z: "Iterable[str]") -> int: ...

var: list[str]
"""Docstring override from the .pyi file."""

class Class:
attr: int
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/type_stub.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<module type_stub # This module has an a…
<function def func(x: str, y: Any, z: Iterable[str]) -> int: ... # A simple function.>
<var var: list[str] = [] # A simple variable.>
<var var: list[str] = [] # Docstring override f…>
<class type_stub.Class
<method def __init__(): ...>
<var attr: int = 42 # An attribute>
Expand Down

0 comments on commit 8b99723

Please sign in to comment.