diff options
author | Keewis <keewis@posteo.de> | 2020-08-06 14:08:34 +0200 |
---|---|---|
committer | Keewis <keewis@posteo.de> | 2020-08-06 14:08:34 +0200 |
commit | 4428393403ad98e49459e36085c7f0a85a627bab (patch) | |
tree | fd873eff154a22ead1e5984f340b163b13cffb50 /sphinx | |
parent | ca0bd28681afd72c826603eeef5a3ec8fac4e8dd (diff) | |
download | sphinx-git-4428393403ad98e49459e36085c7f0a85a627bab.tar.gz |
translate the functions before attempting to find a matching role
Diffstat (limited to 'sphinx')
-rw-r--r-- | sphinx/ext/napoleon/docstring.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 13a32cff8..d60deff6c 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -1175,6 +1175,22 @@ class NumpyDocstring(GoogleDocstring): 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 rest = [] # type: List[str] @@ -1205,6 +1221,12 @@ class NumpyDocstring(GoogleDocstring): if not items: return [] + # apply type aliases + items = [ + translate(func, description, role) + for func, description, role in items + ] + roles = { 'method': 'meth', 'meth': 'meth', |