Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ def _parse_param_list(self, content, single_element_is_type=False):
# <FUNCNAME> is one of
# <PLAIN_FUNCNAME>
# COLON <ROLE> COLON BACKTICK <PLAIN_FUNCNAME> BACKTICK
# COLON <ROLE> COLON BACKTICK <PLAIN_FUNCNAME> RIGHT_ANGLE_BRACKET <TARGET_NAME> LEFT_ANGLE_BRACKET BACKTICK
# where
# <TARGET_NAME> is a legal sphinx target for cross-linking
# <PLAIN_FUNCNAME> is a legal function name, and
# <ROLE> 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 <class_j>`
# <DESC> is a string describing the function.

_role = r":(?P<role>(py:)?\w+):"
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)`"
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)\s?(?P<target_name>(?:\s?\<\w)[a-zA-Z0-9_\.-]+(?:\>))?`"
_funcplain = r"(?P<name2>[a-zA-Z0-9_\.-]+)"
_funcname = r"(" + _role + _funcbacktick + r"|" + _funcplain + r")"
_funcnamenext = _funcname.replace("role", "rolenext")
Expand Down Expand Up @@ -300,12 +302,16 @@ def _parse_see_also(self, content):
items = []

def parse_item_name(text):
"""Match ':role:`name`' or 'name'."""
"""Match ':role:`name`', ':role:`name <target>`' or 'name'."""
m = self._func_rgx.match(text)
if not m:
self._error_location(f"Error parsing See Also entry {line!r}")
role = m.group("role")
name = m.group("name") if role else m.group("name2")

target_name = m.group("target_name")
if target_name is not None:
name += f" {target_name}"
return name, role, m.end()

rest = []
Expand Down
5 changes: 5 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
some, other, funcs
otherfunc : relationship
:py:meth:`spyder.widgets.mixins.GetHelpMixin.show_object_info`
:py:meth:`int.bit_length <int.bit_length>`

Examples
--------
Expand Down Expand Up @@ -451,6 +452,8 @@ def test_str(doc):
relationship
:py:meth:`spyder.widgets.mixins.GetHelpMixin.show_object_info`
..
:py:meth:`int.bit_length <int.bit_length>`
..

Notes
-----
Expand Down Expand Up @@ -642,6 +645,8 @@ def test_sphinx_str():
relationship
:py:meth:`spyder.widgets.mixins.GetHelpMixin.show_object_info`
..
:py:meth:`int.bit_length <int.bit_length>`
..

.. rubric:: Notes

Expand Down