Skip to content

Commit

Permalink
fix: Don't crash on inspection of method descriptors' docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 2, 2022
1 parent a81f8dc commit 09571bb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/griffe/agents/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,20 @@ def __init__(
self.lines_collection: LinesCollection = lines_collection or LinesCollection()

def _get_docstring(self, node: ObjectNode) -> Docstring | None:
# Access `__doc__` directly to avoid taking the `__doc__` attribute from a parent class.
# access `__doc__` directly to avoid taking the `__doc__` attribute from a parent class
value = getattr(node.obj, "__doc__", None)
if value is None:
return None
try:
# we avoid `inspect.getdoc` to avoid getting
# the `__doc__` attribute from a parent class,
# but we still want to clean the doc
cleaned = cleandoc(value)
except AttributeError:
# triggered on method descriptors
return None
return Docstring(
# `inspect.getdoc` calls `inspect.cleandoc`. We avoid `inspect.getdoc` to avoid taking
# the `__doc__` attribute from a parent class, but we still want to clean the doc.
cleandoc(value),
cleaned,
parser=self.docstring_parser,
parser_options=self.docstring_options,
)
Expand Down

0 comments on commit 09571bb

Please sign in to comment.