Skip to content

Commit

Permalink
expect inspect.signature to raise, fix #678 (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils authored Jul 10, 2024
1 parent d571959 commit 552378f
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 75 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
([#709](https://github.com/mitmproxy/pdoc/pull/709), @mhils)
- Fix a TypeError when trying to parse modules that implement `__dir__` incorrectly.
([#710](https://github.com/mitmproxy/pdoc/pull/710), @mhils)
- Fix a bug where a combination of `@dataclass` and `ctypes.Structure` would crash pdoc.
([#711](https://github.com/mitmproxy/pdoc/pull/711), @mhils)

## 2024-06-25: pdoc 14.5.1

Expand Down
21 changes: 12 additions & 9 deletions pdoc/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,18 @@ def docstring(self) -> str:
if doc in _Enum_default_docstrings:
# Don't display default docstring for enum subclasses.
return ""
is_dataclass_with_default_docstring = (
dataclasses.is_dataclass(self.obj)
# from https://github.com/python/cpython/blob/3.10/Lib/dataclasses.py
and doc
== self.obj.__name__
+ str(inspect.signature(self.obj)).replace(" -> None", "")
)
if is_dataclass_with_default_docstring:
return ""
if dataclasses.is_dataclass(self.obj) and doc.startswith(self.obj.__name__):
try:
sig = inspect.signature(self.obj)
except Exception:
pass
else:
# from https://github.com/python/cpython/blob/3.10/Lib/dataclasses.py
is_dataclass_with_default_docstring = doc == self.obj.__name__ + str(
sig
).replace(" -> None", "")
if is_dataclass_with_default_docstring:
return ""
return doc

@cached_property
Expand Down
Loading

0 comments on commit 552378f

Please sign in to comment.