Skip to content

Commit c8e2003

Browse files
committed
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 <QImage.save>` This commit allows the regex to parse the sphinx target, which is the section between the angled brackets.
1 parent acad4ec commit c8e2003

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

numpydoc/docscrape.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,16 @@ def _parse_param_list(self, content, single_element_is_type=False):
257257
# <FUNCNAME> is one of
258258
# <PLAIN_FUNCNAME>
259259
# COLON <ROLE> COLON BACKTICK <PLAIN_FUNCNAME> BACKTICK
260+
# COLON <ROLE> COLON BACKTICK <PLAIN_FUNCNAME> RIGHT_ANGLE_BRACKET <TARGET_NAME> LEFT_ANGLE_BRACKET BACKTICK
260261
# where
262+
# <TARGET_NAME> is a legal sphinx target for cross-linking
261263
# <PLAIN_FUNCNAME> is a legal function name, and
262264
# <ROLE> is any nonempty sequence of word characters.
263-
# Examples: func_f1 :meth:`func_h1` :obj:`~baz.obj_r` :class:`class_j`
265+
# Examples: func_f1 :meth:`func_h1` :obj:`~baz.obj_r` :class:`class_j` :class:`class_j <class_j>`
264266
# <DESC> is a string describing the function.
265267

266268
_role = r":(?P<role>(py:)?\w+):"
267-
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)`"
269+
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)\s?(?P<target_name>(?:\s?\<\w)[a-zA-Z0-9_\.-]+(?:\>))?`"
268270
_funcplain = r"(?P<name2>[a-zA-Z0-9_\.-]+)"
269271
_funcname = r"(" + _role + _funcbacktick + r"|" + _funcplain + r")"
270272
_funcnamenext = _funcname.replace("role", "rolenext")
@@ -300,7 +302,7 @@ def _parse_see_also(self, content):
300302
items = []
301303

302304
def parse_item_name(text):
303-
"""Match ':role:`name`' or 'name'."""
305+
"""Match ':role:`name`', ':role:`name <target>`' or 'name'."""
304306
m = self._func_rgx.match(text)
305307
if not m:
306308
self._error_location(f"Error parsing See Also entry {line!r}")

0 commit comments

Comments
 (0)