diff options
| author | Keewis <keewis@posteo.de> | 2020-05-29 19:12:31 +0200 |
|---|---|---|
| committer | Keewis <keewis@posteo.de> | 2020-07-16 00:22:56 +0200 |
| commit | ad89b1f76a5a031e14022c96d678a6240061eb11 (patch) | |
| tree | 0d6b11ddfc446cf37274fe935ea16138b27f3165 /sphinx | |
| parent | 2882c3465adc37d86107cca0dcd51d383a288f82 (diff) | |
| download | sphinx-git-ad89b1f76a5a031e14022c96d678a6240061eb11.tar.gz | |
replace the hard-coded mapping of translations with a config option
Diffstat (limited to 'sphinx')
| -rw-r--r-- | sphinx/ext/napoleon/__init__.py | 5 | ||||
| -rw-r--r-- | sphinx/ext/napoleon/docstring.py | 14 |
2 files changed, 10 insertions, 9 deletions
diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index 2b1818425..e3b03fd75 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -41,6 +41,7 @@ class Config: napoleon_use_param = True napoleon_use_rtype = True napoleon_use_keyword = True + napoleon_numpy_type_aliases = None napoleon_custom_sections = None .. _Google style: @@ -236,6 +237,9 @@ class Config: :returns: *bool* -- True if successful, False otherwise + napoleon_numpy_type_aliases : :obj:`dict` (Defaults to None) + Add a mapping of strings to string, translating types. + napoleon_custom_sections : :obj:`list` (Defaults to None) Add a list of custom sections to include, expanding the list of parsed sections. @@ -263,6 +267,7 @@ class Config: 'napoleon_use_param': (True, 'env'), 'napoleon_use_rtype': (True, 'env'), 'napoleon_use_keyword': (True, 'env'), + 'napoleon_numpy_type_aliases': (None, 'env'), 'napoleon_custom_sections': (None, 'env') } diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index ae5ba4456..63e2df6bc 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -840,7 +840,7 @@ def _tokenize_type_spec(spec): return _recombine_set_tokens(tokens) -def _convert_numpy_type_spec(_type): +def _convert_numpy_type_spec(_type, translations): def token_type(token): if token.startswith(" ") or token.endswith(" "): type_ = "delimiter" @@ -866,13 +866,6 @@ def _convert_numpy_type_spec(_type): for token in tokens ] - # TODO: make this configurable - translations = { - "sequence": ":term:`sequence`", - "mapping": ":term:`mapping`", - "dict-like": ":term:`dict-like <mapping>`", - } - # don't use the object role if it's not necessary default_translation = ( ":obj:`{}`" @@ -1002,7 +995,10 @@ class NumpyDocstring(GoogleDocstring): _name, _type = line, '' _name, _type = _name.strip(), _type.strip() _name = self._escape_args_and_kwargs(_name) - _type = _convert_numpy_type_spec(_type) + _type = _convert_numpy_type_spec( + _type, + translations=self._config.napoleon_numpy_type_aliases or {}, + ) if prefer_type and not _type: _type, _name = _name, _type |
