Skip to content

Commit 1e61a53

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 eb831f4 commit 1e61a53

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
@@ -256,14 +256,16 @@ def _parse_param_list(self, content, single_element_is_type=False):
256256
# <FUNCNAME> is one of
257257
# <PLAIN_FUNCNAME>
258258
# COLON <ROLE> COLON BACKTICK <PLAIN_FUNCNAME> BACKTICK
259+
# COLON <ROLE> COLON BACKTICK <PLAIN_FUNCNAME> RIGHT_ANGLE_BRACKET <TARGET_NAME> LEFT_ANGLE_BRACKET BACKTICK
259260
# where
261+
# <TARGET_NAME> is a legal sphinx target for cross-linking
260262
# <PLAIN_FUNCNAME> is a legal function name, and
261263
# <ROLE> is any nonempty sequence of word characters.
262-
# Examples: func_f1 :meth:`func_h1` :obj:`~baz.obj_r` :class:`class_j`
264+
# Examples: func_f1 :meth:`func_h1` :obj:`~baz.obj_r` :class:`class_j` :class:`class_j <class_j>`
263265
# <DESC> is a string describing the function.
264266

265267
_role = r":(?P<role>(py:)?\w+):"
266-
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)`"
268+
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)\s?(?P<target_name>(?:\s?\<\w)[a-zA-Z0-9_\.-]+(?:\>))?`"
267269
_funcplain = r"(?P<name2>[a-zA-Z0-9_\.-]+)"
268270
_funcname = r"(" + _role + _funcbacktick + r"|" + _funcplain + r")"
269271
_funcnamenext = _funcname.replace("role", "rolenext")
@@ -299,7 +301,7 @@ def _parse_see_also(self, content):
299301
items = []
300302

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

0 commit comments

Comments
 (0)