mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
translate the functions before attempting to find a matching role
This commit is contained in:
parent
ca0bd28681
commit
4428393403
@ -1175,6 +1175,22 @@ class NumpyDocstring(GoogleDocstring):
|
|||||||
|
|
||||||
return None
|
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]
|
||||||
|
|
||||||
@ -1205,6 +1221,12 @@ class NumpyDocstring(GoogleDocstring):
|
|||||||
if not items:
|
if not items:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# apply type aliases
|
||||||
|
items = [
|
||||||
|
translate(func, description, role)
|
||||||
|
for func, description, role in items
|
||||||
|
]
|
||||||
|
|
||||||
roles = {
|
roles = {
|
||||||
'method': 'meth',
|
'method': 'meth',
|
||||||
'meth': 'meth',
|
'meth': 'meth',
|
||||||
|
@ -1400,6 +1400,38 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None)
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(expected, actual)
|
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()
|
||||||
|
app.builder.env.intersphinx_inventory = {
|
||||||
|
"py:func": {"funcs": (), "otherfunc": ()},
|
||||||
|
"py:meth": {"some": (), "MyClass.other": ()},
|
||||||
|
}
|
||||||
|
actual = str(NumpyDocstring(docstring, config, app, "method"))
|
||||||
|
|
||||||
|
expected = """\
|
||||||
|
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:meth:`some`, :meth:`MyClass.other`, :func:`funcs`
|
||||||
|
\n\
|
||||||
|
:func:`~my_package.otherfunc`
|
||||||
|
relationship
|
||||||
|
"""
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
def test_colon_in_return_type(self):
|
def test_colon_in_return_type(self):
|
||||||
docstring = """
|
docstring = """
|
||||||
|
Loading…
Reference in New Issue
Block a user