Skip to content

Commit 1930e6e

Browse files
committed
fix: dynamic importing module, and replacing attr doc
1 parent c576115 commit 1930e6e

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

quartodoc/autosummary.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ def replace_docstring(obj: dc.Object | dc.Alias, f=None):
199199
# since griffe reads class docstrings from the .__init__ method, this should
200200
# also have the effect of updating the class docstring.
201201
if isinstance(obj, dc.Class):
202-
for func_obj in obj.functions.values():
203-
replace_docstring(func_obj)
202+
for child_obj in obj.members.values():
203+
replace_docstring(child_obj)
204204

205205
if f is None:
206206
mod = importlib.import_module(obj.module.canonical_path)
@@ -253,12 +253,14 @@ def dynamic_alias(
253253
except ValueError:
254254
mod_name, object_path = path, None
255255

256+
# get underlying object dynamically ----
257+
256258
mod = importlib.import_module(mod_name)
257259

258260
# Case 1: path is just to a module
259261
if object_path is None:
260-
attr = get_object(path)
261-
canonical_path = attr.__name__
262+
attr = mod
263+
canonical_path = mod.__name__
262264

263265
# Case 2: path is to a member of a module
264266
else:
@@ -284,7 +286,7 @@ def dynamic_alias(
284286

285287
attr = crnt_part
286288

287-
# start loading things with griffe ----
289+
# start loading object with griffe ----
288290

289291
if target:
290292
obj = get_object(target, loader=loader)

quartodoc/tests/test_basic.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from quartodoc import get_object, get_function, MdRenderer
22
from griffe.docstrings import dataclasses as ds
3+
from griffe import dataclasses as dc
34

45

56
def test_get_function():
@@ -52,3 +53,34 @@ def test_render_attribute():
5253
MdRenderer().render(a)
5354
== "`tests.example_attribute.a`\n\nI am an attribute docstring"
5455
)
56+
57+
58+
def test_get_object_dynamic_module_root():
59+
obj = get_object("quartodoc", dynamic=True)
60+
assert isinstance(obj, dc.Module)
61+
assert obj.path == "quartodoc"
62+
63+
64+
def test_get_object_dynamic_module():
65+
obj = get_object("quartodoc.renderers", dynamic=True)
66+
assert isinstance(obj, dc.Module)
67+
assert obj.path == "quartodoc.renderers"
68+
69+
70+
def test_get_object_dynamic_function():
71+
obj = get_object("quartodoc.tests.example_dynamic:f", dynamic=True)
72+
assert obj.docstring.value.endswith("I am a note")
73+
74+
75+
def test_get_object_dynamic_class_method_doc():
76+
obj = get_object("quartodoc.tests.example_dynamic:AClass", dynamic=True)
77+
78+
meth = obj.members["dynamic_doc"]
79+
assert meth.docstring.value == "A dynamic method"
80+
81+
82+
def test_get_object_dynamic_class_method_doc():
83+
obj = get_object("quartodoc.tests.example_dynamic:AClass", dynamic=True)
84+
85+
meth = obj.members["dynamic_create"]
86+
assert meth.docstring.value == "A dynamic method"

0 commit comments

Comments
 (0)