From c8e2003320a92d6a8872273182704970bfaea515 Mon Sep 17 00:00:00 2001 From: Ognyan Moore Date: Tue, 21 May 2024 22:26:19 -0400 Subject: [PATCH] See Also Parser Recognizes Sphinx XREF The See Also section raises a ValueError when it encounters a valid sphinx cross-reference such as :meth:`QImage.save ` This commit allows the regex to parse the sphinx target, which is the section between the angled brackets. --- numpydoc/docscrape.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index a241dc21..da24b0b1 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -257,14 +257,16 @@ def _parse_param_list(self, content, single_element_is_type=False): # is one of # # COLON COLON BACKTICK BACKTICK + # COLON COLON BACKTICK RIGHT_ANGLE_BRACKET LEFT_ANGLE_BRACKET BACKTICK # where + # is a legal sphinx target for cross-linking # is a legal function name, and # is any nonempty sequence of word characters. - # Examples: func_f1 :meth:`func_h1` :obj:`~baz.obj_r` :class:`class_j` + # Examples: func_f1 :meth:`func_h1` :obj:`~baz.obj_r` :class:`class_j` :class:`class_j ` # is a string describing the function. _role = r":(?P(py:)?\w+):" - _funcbacktick = r"`(?P(?:~\w+\.)?[a-zA-Z0-9_\.-]+)`" + _funcbacktick = r"`(?P(?:~\w+\.)?[a-zA-Z0-9_\.-]+)\s?(?P(?:\s?\<\w)[a-zA-Z0-9_\.-]+(?:\>))?`" _funcplain = r"(?P[a-zA-Z0-9_\.-]+)" _funcname = r"(" + _role + _funcbacktick + r"|" + _funcplain + r")" _funcnamenext = _funcname.replace("role", "rolenext") @@ -300,7 +302,7 @@ def _parse_see_also(self, content): items = [] def parse_item_name(text): - """Match ':role:`name`' or 'name'.""" + """Match ':role:`name`', ':role:`name `' or 'name'.""" m = self._func_rgx.match(text) if not m: self._error_location(f"Error parsing See Also entry {line!r}")