Skip to content

Commit

Permalink
refactor: Only consider presence/absence for docstrings truthiness, n…
Browse files Browse the repository at this point in the history
…ot emptiness of their value

Griffe extensions will often manipulate the parsed sections
of a docstring rather than its raw value. It means that,
often times docstrings will have an empty value
but dynamically inserted sections. In that case a docstring
truthiness should evaluate to true, not false.

We don't want to parse sections to evaluate truthiness
(we tolerate it in extensions, but should avoid it
in Griffe's main logic), so we simply base our evaluation
on the absence or presence of the docstring (none or instance).
  • Loading branch information
pawamoy committed Oct 16, 2023
1 parent 66eb0c2 commit 4c49611
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ def __init__(
self.parser_options: dict[str, Any] = parser_options or {}
"""The configured parsing options."""

def __bool__(self) -> bool:
return bool(self.value)

@property
def lines(self) -> list[str]:
"""The lines of the docstring."""
Expand Down Expand Up @@ -382,12 +379,12 @@ def __len__(self) -> int:

@property
def has_docstring(self) -> bool:
"""Whether this object has a non-empty docstring."""
"""Whether this object has a docstring (empty or not)."""
return bool(self.docstring)

@property
def has_docstrings(self) -> bool:
"""Whether this object or any of its members has a non-empty docstring."""
"""Whether this object or any of its members has a docstring (empty or not)."""
if self.has_docstring:
return True
return any(member.has_docstrings for member in self.members.values())
Expand Down

0 comments on commit 4c49611

Please sign in to comment.