Skip to content

Commit

Permalink
always use :obj: instead of searching the inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis committed Aug 7, 2020
1 parent 4428393 commit 95c861f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 62 deletions.
36 changes: 2 additions & 34 deletions sphinx/ext/napoleon/docstring.py
Expand Up @@ -1131,11 +1131,6 @@ def _parse_numpydoc_see_also_section(self, content: List[str]) -> List[str]:
func_name1, func_name2, :meth:`func_name`, func_name3
"""
try:
inventory = self._app.builder.env.intersphinx_inventory # type: ignore
except AttributeError:
inventory = {}

items = []

def parse_item_name(text: str) -> Tuple[str, str]:
Expand Down Expand Up @@ -1227,41 +1222,14 @@ def translate(func, description, role):
for func, description, role in items
]

roles = {
'method': 'meth',
'meth': 'meth',
'function': 'func',
'func': 'func',
'class': 'class',
'exception': 'exc',
'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, '')
func_role = 'obj'
lines = [] # type: List[str]
last_had_desc = True
for func, desc, role in items:
if not role:
raw_role = search_inventory(inventory, func, hint=func_role)
role = roles.get(raw_role, raw_role)

if role:
link = ':%s:`%s`' % (role, func)
elif func_role:
link = ':%s:`%s`' % (func_role, func)
else:
link = "`%s`_" % func
link = ':%s:`%s`' % (func_role, func)
if desc or last_had_desc:
lines += ['']
lines += [link]
Expand Down
31 changes: 3 additions & 28 deletions tests/test_ext_napoleon_docstring.py
Expand Up @@ -1365,37 +1365,16 @@ def test_see_also_refs(self):

config = Config()
app = mock.Mock()
app.builder.env = None
actual = str(NumpyDocstring(docstring, config, app, "method"))

expected = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
.. seealso::
:meth:`some`, :meth:`other`, :meth:`funcs`
\n\
:meth:`otherfunc`
relationship
"""
self.assertEqual(expected, actual)

config = Config()
app = mock.Mock()
app.builder.env.intersphinx_inventory = {
"py:func": {"funcs": (), "otherfunc": ()},
"py:meth": {"some": (), "other": ()},
}
actual = str(NumpyDocstring(docstring, config, app, "method"))

expected = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
.. seealso::
:meth:`some`, :meth:`other`, :func:`funcs`
:obj:`some`, :obj:`other`, :obj:`funcs`
\n\
:func:`otherfunc`
:obj:`otherfunc`
relationship
"""
self.assertEqual(expected, actual)
Expand All @@ -1415,18 +1394,14 @@ def test_see_also_refs(self):
}
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`
:obj:`some`, :obj:`MyClass.other`, :func:`funcs`
\n\
:func:`~my_package.otherfunc`
relationship
Expand Down

0 comments on commit 95c861f

Please sign in to comment.