Skip to content

Commit 4a5fd51

Browse files
iFreilichtmhils
andauthored
Fix TypeError when cls.__module__ is None (#770)
* Fix TypeError when cls.__module__ is None Trying to use `pdoc -o` instead of `pdoc` in my project caused a long stacktrace with this error at the end: File "/Users/feuh/.../.venv/lib/python3.12/site-packages/pdoc/doc.py", line 640, in _var_annotations _safe_getattr(cls, "__module__", "") + "." + cls.__qualname__ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' This was caused by one class' `__module__` attribute being `None`. I could not find the reason why that happens and why it happens only when using `-o`, but this change ensures it won't happen again. * add parentheses --------- Co-authored-by: Maximilian Hils <[email protected]>
1 parent 2746a02 commit 4a5fd51

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pdoc/doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def _var_annotations(self) -> dict[str, type]:
637637
for attr, unresolved_annotation in dynamic_annotations.items():
638638
cls_annotations[attr] = unresolved_annotation
639639
cls_fullname = (
640-
_safe_getattr(cls, "__module__", "") + "." + cls.__qualname__
640+
(_safe_getattr(cls, "__module__", "") or "") + "." + cls.__qualname__
641641
).lstrip(".")
642642

643643
new_annotations = {

0 commit comments

Comments
 (0)