diff --git a/pydoctor/epydoc2stan.py b/pydoctor/epydoc2stan.py index c5213936d..2df8d19eb 100644 --- a/pydoctor/epydoc2stan.py +++ b/pydoctor/epydoc2stan.py @@ -1269,7 +1269,8 @@ def __init__(self, document:nodes.document, def _transform(self, node:nodes.title_reference) -> None: ctx = self.ctx module = self.module - _, target = parse_reference(node) + ref = parse_reference(node) + target = ref.target # we're setting two attributes here: 'refuri' and 'rawtarget'. # 'refuri' might already be created by the colorizer or docstring parser, # but 'rawtarget' is only created from within this transform, so we can @@ -1301,7 +1302,7 @@ def _transform(self, node:nodes.title_reference) -> None: # If we're dealing with an annotation, give precedence to the module's # lookup (wrt PEP 563) lookup_context = module - linker.warn_ambiguous_annotation(module, ctx, target) + # save pre-resolved refuri attribs['refuri'] = '.'.join(chain(lookup_context.expandName(name).split('.'), rest)) diff --git a/pydoctor/node2stan.py b/pydoctor/node2stan.py index 6176821e9..91634d0cb 100644 --- a/pydoctor/node2stan.py +++ b/pydoctor/node2stan.py @@ -11,6 +11,8 @@ from docutils import nodes, frontend, __version_info__ as docutils_version_info from twisted.web.template import Tag +import attr + if TYPE_CHECKING: from twisted.web.template import Flattenable from pydoctor.epydoc.markup import DocstringLinker @@ -58,7 +60,13 @@ def gettext(node: Union[nodes.Node, List[nodes.Node]]) -> List[str]: filtered.extend(gettext(child)) return filtered -def parse_reference(node:nodes.title_reference) -> Tuple[Union[str, Sequence[nodes.Node]], str]: +@attr.s(auto_attribs=True) +class Reference: + label: str | Sequence[nodes.Node] + target: str + rawtarget: str + +def parse_reference(node:nodes.title_reference) -> Reference: """ Split a reference into (label, target). """ @@ -76,7 +84,7 @@ def parse_reference(node:nodes.title_reference) -> Tuple[Union[str, Sequence[nod # Support linking to functions and methods with () at the end if target.endswith('()'): target = target[:len(target)-2] - return label, target + return Reference(label, target, node.attributes.get('rawtarget', target)) _TARGET_RE = re.compile(r'^(.*?)\s*<(?:URI:|URL:)?([^<>]+)>$') _VALID_IDENTIFIER_RE = re.compile('[^0-9a-zA-Z_]') @@ -131,7 +139,9 @@ def visit_obj_reference(self, node: obj_reference) -> None: self._handle_reference(node, link_func=self._linker.link_to) def _handle_reference(self, node: nodes.title_reference, link_func: Callable[[str, "Flattenable"], "Flattenable"]) -> None: - node_label, target = parse_reference(node) + ref = parse_reference(node) + node_label = ref.label + target = ref.target label: "Flattenable" if not isinstance(node_label, str): label = node2stan(node_label, self._linker)