mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8051 from keewis/fix-see_also
use the obj role for all See Also items
This commit is contained in:
@@ -1188,6 +1188,41 @@ class NumpyDocstring(GoogleDocstring):
|
|||||||
items.append((name, list(rest), role))
|
items.append((name, list(rest), role))
|
||||||
del rest[:]
|
del rest[:]
|
||||||
|
|
||||||
|
def search_inventory(inventory, name, hint=None):
|
||||||
|
roles = list(inventory.keys())
|
||||||
|
if hint is not None:
|
||||||
|
preferred = [
|
||||||
|
role
|
||||||
|
for role in roles
|
||||||
|
if role.split(":", 1)[-1].startswith(hint)
|
||||||
|
]
|
||||||
|
roles = preferred + [role for role in roles if role not in preferred]
|
||||||
|
|
||||||
|
for role in roles:
|
||||||
|
objects = inventory[role]
|
||||||
|
found = objects.get(name, None)
|
||||||
|
if found is not None:
|
||||||
|
domain, role = role.split(":", 1)
|
||||||
|
return role
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def translate(func, description, role):
|
||||||
|
translations = self._config.napoleon_type_aliases
|
||||||
|
if role is not None or not translations:
|
||||||
|
return func, description, role
|
||||||
|
|
||||||
|
translated = translations.get(func, func)
|
||||||
|
match = self._name_rgx.match(translated)
|
||||||
|
if not match:
|
||||||
|
return translated, description, role
|
||||||
|
|
||||||
|
groups = match.groupdict()
|
||||||
|
role = groups["role"]
|
||||||
|
new_func = groups["name"] or groups["name2"]
|
||||||
|
|
||||||
|
return new_func, description, role
|
||||||
|
|
||||||
current_func = None
|
current_func = None
|
||||||
rest = [] # type: List[str]
|
rest = [] # type: List[str]
|
||||||
|
|
||||||
@@ -1218,37 +1253,20 @@ class NumpyDocstring(GoogleDocstring):
|
|||||||
if not items:
|
if not items:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
roles = {
|
# apply type aliases
|
||||||
'method': 'meth',
|
items = [
|
||||||
'meth': 'meth',
|
translate(func, description, role)
|
||||||
'function': 'func',
|
for func, description, role in items
|
||||||
'func': 'func',
|
]
|
||||||
'class': 'class',
|
|
||||||
'exception': 'exc',
|
func_role = 'obj'
|
||||||
'exc': 'exc',
|
|
||||||
'object': 'obj',
|
|
||||||
'obj': 'obj',
|
|
||||||
'module': 'mod',
|
|
||||||
'mod': 'mod',
|
|
||||||
'data': 'data',
|
|
||||||
'constant': 'const',
|
|
||||||
'const': 'const',
|
|
||||||
'attribute': 'attr',
|
|
||||||
'attr': 'attr'
|
|
||||||
}
|
|
||||||
if self._what is None:
|
|
||||||
func_role = 'obj'
|
|
||||||
else:
|
|
||||||
func_role = roles.get(self._what, '')
|
|
||||||
lines = [] # type: List[str]
|
lines = [] # type: List[str]
|
||||||
last_had_desc = True
|
last_had_desc = True
|
||||||
for func, desc, role in items:
|
for func, desc, role in items:
|
||||||
if role:
|
if role:
|
||||||
link = ':%s:`%s`' % (role, func)
|
link = ':%s:`%s`' % (role, func)
|
||||||
elif func_role:
|
|
||||||
link = ':%s:`%s`' % (func_role, func)
|
|
||||||
else:
|
else:
|
||||||
link = "`%s`_" % func
|
link = ':%s:`%s`' % (func_role, func)
|
||||||
if desc or last_had_desc:
|
if desc or last_had_desc:
|
||||||
lines += ['']
|
lines += ['']
|
||||||
lines += [link]
|
lines += [link]
|
||||||
|
|||||||
@@ -1455,9 +1455,38 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None)
|
|||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
:meth:`some`, :meth:`other`, :meth:`funcs`
|
:obj:`some`, :obj:`other`, :obj:`funcs`
|
||||||
\n\
|
\n\
|
||||||
:meth:`otherfunc`
|
:obj:`otherfunc`
|
||||||
|
relationship
|
||||||
|
"""
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
docstring = """\
|
||||||
|
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
|
||||||
|
|
||||||
|
See Also
|
||||||
|
--------
|
||||||
|
some, other, :func:`funcs`
|
||||||
|
otherfunc : relationship
|
||||||
|
|
||||||
|
"""
|
||||||
|
translations = {
|
||||||
|
"other": "MyClass.other",
|
||||||
|
"otherfunc": ":func:`~my_package.otherfunc`",
|
||||||
|
}
|
||||||
|
config = Config(napoleon_type_aliases=translations)
|
||||||
|
app = mock.Mock()
|
||||||
|
actual = str(NumpyDocstring(docstring, config, app, "method"))
|
||||||
|
|
||||||
|
expected = """\
|
||||||
|
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:obj:`some`, :obj:`MyClass.other`, :func:`funcs`
|
||||||
|
\n\
|
||||||
|
:func:`~my_package.otherfunc`
|
||||||
relationship
|
relationship
|
||||||
"""
|
"""
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|||||||
Reference in New Issue
Block a user