diff --git a/src/griffe/dataclasses.py b/src/griffe/dataclasses.py index 462f55dd..6df29112 100644 --- a/src/griffe/dataclasses.py +++ b/src/griffe/dataclasses.py @@ -350,7 +350,12 @@ def has_docstring(self) -> bool: @property def has_docstrings(self) -> bool: """Tell if this object or any of its members has a non-empty docstring.""" - return self.has_docstring or any(member.has_docstrings for member in self.members.values()) # noqa: DAR201 + if self.has_docstring: # noqa: DAR201 + return True + for member in self.members.values(): + if (not member.is_alias or member.resolved) and member.has_docstring: # type: ignore[union-attr] + return True + return False def member_is_exported(self, member: Object | Alias, explicitely: bool = True) -> bool: """Tell if a member of this object is "exported". diff --git a/tests/helpers.py b/tests/helpers.py index b2117d7e..73b0f7ca 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -31,7 +31,7 @@ def temporary_pyfile(code: str) -> Iterator[tuple[str, Path]]: """ with tempfile.TemporaryDirectory(prefix=TMPDIR_PREFIX) as tmpdir: tmpfile = Path(tmpdir) / "module.py" - tmpfile.write_text(code) + tmpfile.write_text(dedent(code)) yield "module", tmpfile @@ -96,7 +96,7 @@ def temporary_inspected_module(code: str) -> Iterator[Module]: Yields: The inspected module. """ - with temporary_pyfile(dedent(code)) as (name, path): + with temporary_pyfile(code) as (name, path): try: yield inspect(name, filepath=path) finally: diff --git a/tests/test_loader.py b/tests/test_loader.py new file mode 100644 index 00000000..2db54d88 --- /dev/null +++ b/tests/test_loader.py @@ -0,0 +1,14 @@ +"""Tests for the `loader` module.""" + +from griffe.loader import GriffeLoader +from tests.helpers import temporary_pyfile + + +def test_has_docstrings_does_not_try_to_resolve_alias(): + """Assert that checkins presence of docstrings does not trigger alias resolution.""" + with temporary_pyfile("""from abc import abstractmethod""") as (module_name, path): + loader = GriffeLoader(search_paths=[path.parent]) + module = loader.load_module(module_name) + loader.resolve_aliases() + assert "abstractmethod" in module.members + assert not module.has_docstrings