Skip to content

Commit d4140b4

Browse files
authored
Merge pull request #327 from machow/fix-alias-method-members
fix: do not exclude child methods on alias classes
2 parents c0c57a7 + 6b339ea commit d4140b4

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

quartodoc/builder/blueprint.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,16 @@ def _fetch_members(self, el: Auto, obj: dc.Object | dc.Alias):
376376
if not el.include_private:
377377
options = {k: v for k, v in options.items() if not k.startswith("_")}
378378

379-
if not (el.include_imports or el.include_inherited):
379+
if not el.include_imports and obj.is_module:
380380
options = {k: v for k, v in options.items() if not v.is_alias}
381381

382+
if not el.include_inherited and obj.is_class:
383+
# aliases are kept only if their parent is the current obj
384+
# i.e. they do not belong to a parent class
385+
options = {
386+
k: v for k, v in options.items() if (v.parent is obj or not v.is_alias)
387+
}
388+
382389
# resolve any remaining aliases ----
383390
# the reamining filters require attributes on the target object.
384391
for obj in options.values():

quartodoc/tests/example_alias_target.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from quartodoc.tests.example_alias_target__nested import ( # noqa: F401
22
nested_alias_target,
3+
NestedClass as ClassAlias,
34
tabulate as external_alias,
45
)
56

quartodoc/tests/example_alias_target__nested.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@
77

88
def nested_alias_target():
99
"""A nested alias target"""
10+
11+
12+
class Parent:
13+
def parent_method(self):
14+
"""p1 method"""
15+
16+
17+
class NestedClass(Parent):
18+
def f(self):
19+
"""a method"""
20+
21+
manually_attached = nested_alias_target

quartodoc/tests/test_builder_blueprint.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ def test_blueprint_visit_class(bp, dynamic):
9797
assert res.members[0].obj.path == path.replace(":", ".") + ".a_method"
9898

9999

100+
@pytest.mark.parametrize("dynamic", [False, True])
101+
def test_blueprint_visit_class_alias(bp, dynamic):
102+
path = "quartodoc.tests.example_alias_target:ClassAlias"
103+
auto = lo.Auto(name=path, dynamic=dynamic)
104+
res = bp.visit(auto)
105+
106+
assert isinstance(res, lo.DocClass)
107+
108+
if not dynamic:
109+
# currently, griffe doesn't know that the function manually attached
110+
# to the class is a function, and not an attribute.
111+
assert len(res.members) == 1
112+
assert res.members[0].name == "f"
113+
else:
114+
assert len(res.members) == 2
115+
assert res.members[0].name == "f"
116+
assert res.members[1].name == "manually_attached"
117+
118+
100119
@pytest.mark.parametrize("dynamic", [False, True])
101120
def test_blueprint_visit_module(bp, dynamic):
102121
path = "quartodoc.tests.example"

0 commit comments

Comments
 (0)