Skip to content

Commit c576115

Browse files
committed
fix: preview works when alias can't resolve target
1 parent df3a68b commit c576115

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

quartodoc/ast.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import warnings
4+
35
from enum import Enum
46
from dataclasses import dataclass
57
from griffe.docstrings import dataclasses as ds
@@ -179,7 +181,15 @@ def fields(el: dc.Object):
179181

180182
@dispatch
181183
def fields(el: dc.ObjectAliasMixin):
182-
return fields(el.target)
184+
try:
185+
return fields(el.target)
186+
except dc.AliasResolutionError:
187+
warnings.warn(
188+
f"Could not resolve Alias target `{el.target_path}`."
189+
" This often occurs because the module was not loaded (e.g. it is a"
190+
" package outside of your package)."
191+
)
192+
return ["name", "target_path"]
183193

184194

185195
@dispatch

quartodoc/tests/test_ast.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ def test_preview_no_fail(capsys):
7575
assert "get_object" in res.out
7676

7777

78+
def test_preview_warn_alias_no_load():
79+
# fetch an alias to pydantic.BaseModel, without loading pydantic
80+
# attempting to get alias.target will fail, but preview should still work.
81+
obj = get_object("quartodoc.ast.BaseModel", load_aliases=False)
82+
with pytest.warns(UserWarning) as record:
83+
qast.preview(obj)
84+
85+
msg = record[0].message.args[0]
86+
assert "Could not resolve Alias target `pydantic.BaseModel`" in msg
87+
88+
7889
@pytest.mark.parametrize(
7990
"text, dst",
8091
[("One\n---\nab\n\nTwo\n---\n\ncd", [("One", "ab\n\n"), ("Two", "\ncd")])],

0 commit comments

Comments
 (0)