Skip to content

Commit b51b45a

Browse files
lint fixes
1 parent 8ee9835 commit b51b45a

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/mkdocstrings_handlers/python_xref/crossref.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,28 +318,32 @@ def _error(self, msg: str, just_warn: bool = False) -> None:
318318
self._ok = just_warn
319319

320320

321-
def substitute_relative_crossrefs(obj: Object, checkref: Optional[Callable[[str], bool]] = None) -> None:
321+
def substitute_relative_crossrefs(
322+
obj: Alias|Object,
323+
checkref: Optional[Callable[[str], bool]] = None,
324+
) -> None:
322325
"""Recursively expand relative cross-references in all docstrings in tree.
323326
324327
Arguments:
325328
obj: a Griffe [Object][griffe.] whose docstrings should be modified
326329
checkref: optional function to check whether computed cross-reference is valid.
327330
Should return True if valid, False if not valid.
328331
"""
332+
if isinstance(obj, Alias):
333+
try:
334+
obj = obj.target
335+
except GriffeError:
336+
# If alias could not be resolved, it probably refers
337+
# to an external package, not be documented.
338+
return
339+
329340
doc = obj.docstring
330341

331342
if doc is not None:
332343
doc.value = _RE_CROSSREF.sub(_RelativeCrossrefProcessor(doc, checkref=checkref), doc.value)
333344

334345
for member in obj.members.values():
335-
if isinstance(member, Alias):
336-
try:
337-
member = member.target
338-
except GriffeError as ex:
339-
# If alias could not be resolved, it probably refers
340-
# to an external package, not be documented.
341-
pass
342-
if isinstance(member, Object): # pragma: no branch
346+
if isinstance(member, (Alias,Object)): # pragma: no branch
343347
substitute_relative_crossrefs(member, checkref=checkref)
344348

345349
def doc_value_offset_to_location(doc: Docstring, offset: int) -> tuple[int,int]:

tests/project/src/myproj/pkg/dataclass.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Dataclass example
3+
"""
14

25
from dataclasses import dataclass, field
36

@@ -18,5 +21,5 @@ class Dataclass:
1821
example: [`content`][(c).]
1922
"""
2023

21-
def method(self) -> str:
24+
def method(self) -> None:
2225
"""Example method."""

tests/test_crossref.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ def test_doc_value_offset_to_location() -> None:
267267
assert doc_value_offset_to_location(doc3, 6) == (3, 3)
268268

269269
def test_griffe() -> None:
270+
"""
271+
Test substitution on griffe rep of local project
272+
Returns:
273+
274+
"""
270275
this_dir = Path(__file__).parent
271276
test_src_dir = this_dir / "project" / "src"
272277
myproj = griffe.load(
273278
"myproj",
274279
search_paths = [ test_src_dir ],
275280
)
276281
substitute_relative_crossrefs(myproj)
277-
print(myproj)
282+
# TODO - grovel output

0 commit comments

Comments
 (0)