Skip to content

Commit 54ed4d7

Browse files
authored
fix a bug where type aliases wouldn't be linked (#798)
1 parent b4afbde commit 54ed4d7

4 files changed

Lines changed: 7 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## Unreleased: pdoc next
66

7+
- Fix a bug where type aliases wouldn't be linked.
8+
([#798](https://github.com/mitmproxy/pdoc/pull/798), @mhils)
79
- Fix a bug where invalid Numpydoc docstrings would raise an exception.
810
([#789](https://github.com/mitmproxy/pdoc/pull/789), @mhils)
911
- Improve debuggability of docstring processing

pdoc/doc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,9 @@ def annotation_str(self) -> str:
11691169
"""The variable's type annotation as a pretty-printed str."""
11701170
if self.annotation is not empty:
11711171
formatted = formatannotation(self.annotation)
1172+
# type aliases don't include the module name in their __repr__, so we add it here.
1173+
if isinstance(self.annotation, TypeAliasType):
1174+
formatted = f"{self.annotation.__module__}.{formatted}"
11721175
return f": {_remove_collections_abc(formatted)}"
11731176
else:
11741177
return ""

test/testdata/misc_py312.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ <h1 class="modulename">
130130
</section>
131131
<section id="foo">
132132
<div class="attr variable">
133-
<span class="name">foo</span><span class="annotation">: MyType</span>
133+
<span class="name">foo</span><span class="annotation">: <a href="#MyType">MyType</a></span>
134134

135135

136136
</div>

test/testdata/misc_py312.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<module misc_py312 # Testing features tha…
22
<var MyType = int # A custom Python 3.12…>
3-
<var foo: MyType # A custom type instan…>
3+
<var foo: misc_py312.MyType # A custom type instan…>
44
<var MyTypeWithoutDocstring = int>
55
<var MyTypeClassic: TypeAlias = int # inherited from builtins.int, A "classic" typing.T…>
66
<class misc_py312.NamedTupleExample # An example for a typ…

0 commit comments

Comments
 (0)