diff options
author | Keewis <keewis@posteo.de> | 2020-08-04 14:35:33 +0200 |
---|---|---|
committer | Keewis <keewis@posteo.de> | 2020-08-04 14:35:33 +0200 |
commit | d9fb3bc25cecdcca78172e39b6b62723ba7f4dc5 (patch) | |
tree | a599aa5146182af3341f7a4b7f2c825da07b9f15 | |
parent | a721631a541db298f7f9807c9db8433e928cb20b (diff) | |
download | sphinx-git-d9fb3bc25cecdcca78172e39b6b62723ba7f4dc5.tar.gz |
search the role for See Also items in the intersphinx inventory
-rw-r--r-- | sphinx/ext/napoleon/docstring.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 95fb1e538..b1e5ca374 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -1131,6 +1131,7 @@ class NumpyDocstring(GoogleDocstring): func_name1, func_name2, :meth:`func_name`, func_name3 """ + inventory = getattr(self._app.builder.env, "intersphinx_inventory", {}) items = [] def parse_item_name(text: str) -> Tuple[str, str]: @@ -1151,6 +1152,25 @@ class NumpyDocstring(GoogleDocstring): items.append((name, list(rest), role)) 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 + current_func = None rest = [] # type: List[str] @@ -1206,6 +1226,10 @@ class NumpyDocstring(GoogleDocstring): 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: |