|
20 | 20 | import sys
|
21 | 21 | from typing import Any, Callable, List, Optional, cast
|
22 | 22 |
|
23 |
| -from griffe import Docstring, Object |
| 23 | +from griffe import Alias, Docstring, GriffeError, Object |
24 | 24 | from mkdocstrings import get_logger
|
25 | 25 |
|
26 | 26 | __all__ = [
|
@@ -318,21 +318,32 @@ def _error(self, msg: str, just_warn: bool = False) -> None:
|
318 | 318 | self._ok = just_warn
|
319 | 319 |
|
320 | 320 |
|
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: |
322 | 325 | """Recursively expand relative cross-references in all docstrings in tree.
|
323 | 326 |
|
324 | 327 | Arguments:
|
325 | 328 | obj: a Griffe [Object][griffe.] whose docstrings should be modified
|
326 | 329 | checkref: optional function to check whether computed cross-reference is valid.
|
327 | 330 | Should return True if valid, False if not valid.
|
328 | 331 | """
|
| 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 | + |
329 | 340 | doc = obj.docstring
|
330 | 341 |
|
331 | 342 | if doc is not None:
|
332 | 343 | doc.value = _RE_CROSSREF.sub(_RelativeCrossrefProcessor(doc, checkref=checkref), doc.value)
|
333 | 344 |
|
334 | 345 | for member in obj.members.values():
|
335 |
| - if isinstance(member, Object): # pragma: no branch |
| 346 | + if isinstance(member, (Alias,Object)): # pragma: no branch |
336 | 347 | substitute_relative_crossrefs(member, checkref=checkref)
|
337 | 348 |
|
338 | 349 | def doc_value_offset_to_location(doc: Docstring, offset: int) -> tuple[int,int]:
|
|
0 commit comments