diff options
author | Keewis <keewis@posteo.de> | 2020-08-07 12:43:56 +0200 |
---|---|---|
committer | Keewis <keewis@posteo.de> | 2020-08-07 12:44:22 +0200 |
commit | 95c861facb752daeacca09a118f48f323ffcea32 (patch) | |
tree | c7a09fafcce137d8505144346adec2e0092cd4a7 | |
parent | 4428393403ad98e49459e36085c7f0a85a627bab (diff) | |
download | sphinx-git-95c861facb752daeacca09a118f48f323ffcea32.tar.gz |
always use :obj: instead of searching the inventory
-rw-r--r-- | sphinx/ext/napoleon/docstring.py | 36 | ||||
-rw-r--r-- | tests/test_ext_napoleon_docstring.py | 31 |
2 files changed, 5 insertions, 62 deletions
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index d60deff6c..a7c799697 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -1131,11 +1131,6 @@ class NumpyDocstring(GoogleDocstring): 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]: @@ -1227,41 +1222,14 @@ class NumpyDocstring(GoogleDocstring): 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] diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 57bdf1342..18a7cc88b 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1365,7 +1365,6 @@ otherfunc : relationship config = Config() app = mock.Mock() - app.builder.env = None actual = str(NumpyDocstring(docstring, config, app, "method")) expected = """\ @@ -1373,29 +1372,9 @@ 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) @@ -1415,10 +1394,6 @@ otherfunc : relationship } 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 = """\ @@ -1426,7 +1401,7 @@ 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 |