Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit docstrings from parent classes #339

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ requires-python = ">=3.9"
dependencies = [
"click",
"griffe >= 0.33",
"griffe-inherited-docstrings",
"sphobjinv >= 2.3.1",
"tabulate >= 0.9.0",
"importlib-metadata >= 5.1.0",
Expand Down
3 changes: 3 additions & 0 deletions quartodoc/autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from griffe.dataclasses import Alias
from griffe.docstrings.parsers import Parser, parse
from griffe.docstrings import dataclasses as ds # noqa
from griffe.extensions import Extensions
from griffe_inherited_docstrings import InheritDocstringsExtension
from griffe import dataclasses as dc
from plum import dispatch # noqa
from pathlib import Path
Expand Down Expand Up @@ -123,6 +125,7 @@ def get_object(

if loader is None:
loader = GriffeLoader(
extensions=Extensions(InheritDocstringsExtension()),
docstring_parser=Parser(parser),
docstring_options=get_parser_defaults(parser),
modules_collection=ModulesCollection(),
Expand Down
3 changes: 3 additions & 0 deletions quartodoc/builder/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from griffe.collections import ModulesCollection, LinesCollection
from griffe.docstrings.parsers import Parser
from griffe.exceptions import AliasResolutionError
from griffe.extensions import Extensions
from griffe_inherited_docstrings import InheritDocstringsExtension
from functools import partial
from textwrap import indent

Expand Down Expand Up @@ -145,6 +147,7 @@ class BlueprintTransformer(PydanticTransformer):
def __init__(self, get_object=None, parser="numpy"):
if get_object is None:
loader = GriffeLoader(
extensions=Extensions(InheritDocstringsExtension()),
docstring_parser=Parser(parser),
docstring_options=get_parser_defaults(parser),
modules_collection=ModulesCollection(),
Expand Down
14 changes: 14 additions & 0 deletions quartodoc/tests/__snapshots__/test_renderers.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@

| Name | Description |
| --- | --- |
| [another_method](#quartodoc.tests.example_class.C.another_method) | Another method |
| [some_class_method](#quartodoc.tests.example_class.C.some_class_method) | A class method |
| [some_method](#quartodoc.tests.example_class.C.some_method) | A method |

### another_method { #quartodoc.tests.example_class.C.another_method }

`tests.example_class.C.another_method()`

Another method

### some_class_method { #quartodoc.tests.example_class.C.some_class_method }

`tests.example_class.C.some_class_method()`
Expand Down Expand Up @@ -112,9 +119,16 @@

| Name | Description |
| --- | --- |
| [another_method](#quartodoc.tests.example_class.C.another_method) | Another method |
| [some_class_method](#quartodoc.tests.example_class.C.some_class_method) | A class method |
| [some_method](#quartodoc.tests.example_class.C.some_method) | A method |

## another_method { #quartodoc.tests.example_class.C.another_method }

`tests.example_class.C.another_method()`

Another method

## some_class_method { #quartodoc.tests.example_class.C.some_class_method }

`tests.example_class.C.some_class_method()`
Expand Down
7 changes: 7 additions & 0 deletions quartodoc/tests/example_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self, x: str, y: int):
def some_method(self):
"""A method"""

def another_method(self):
"""Another method"""

@property
def some_property(self):
"""A property"""
Expand All @@ -41,6 +44,10 @@ class Child(C):
def some_new_method(self):
"""A new method"""

# To test inheriting docstring
def another_method(self):
...


class AttributesTable:
"""The short summary.
Expand Down
9 changes: 6 additions & 3 deletions quartodoc/tests/test_builder_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _check_member_names(members, expected):
[
("attributes", {"some_property", "z", "SOME_ATTRIBUTE"}),
("classes", {"D"}),
("functions", {"some_method", "some_class_method"}),
("functions", {"some_method", "another_method", "some_class_method"}),
],
)
def test_blueprint_fetch_members_include_kind_false(kind, removed):
Expand All @@ -227,6 +227,7 @@ def test_blueprint_fetch_members_include_kind_false(kind, removed):
"z",
"some_property",
"some_method",
"another_method",
"D",
"some_class_method",
}
Expand All @@ -240,8 +241,10 @@ def test_blueprint_fetch_members_include_inherited():
auto = lo.Auto(name="quartodoc.tests.example_class.Child", include_inherited=True)
bp = blueprint(auto)

member_names = set([entry.name for entry in bp.members])
assert "some_method" in member_names
members = {entry.name: entry for entry in bp.members}
assert "some_method" in members
assert "another_method" in members
assert "Another method" in members["another_method"].obj.docstring.value


def test_blueprint_fetch_members_dynamic():
Expand Down
Loading