summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeewis <keewis@posteo.de>2020-08-10 13:04:21 +0200
committerKeewis <keewis@posteo.de>2020-08-10 13:04:21 +0200
commit27c252ccbab0a266ed9588355be9af261105b29e (patch)
tree9cef3d898da3aad10c8f7b6aecda5994eb9dc6a1
parent2d180e49c268fa5f9574a1f594e7e253e4c196b7 (diff)
downloadsphinx-git-27c252ccbab0a266ed9588355be9af261105b29e.tar.gz
only preprocess if the preprocessor is enabled
-rw-r--r--sphinx/ext/napoleon/docstring.py11
-rw-r--r--tests/test_ext_napoleon_docstring.py21
2 files changed, 27 insertions, 5 deletions
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index 29799cb06..a629f147f 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -1104,11 +1104,12 @@ 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,
- location=self._get_location(),
- translations=self._config.napoleon_type_aliases or {},
- )
+ if self._config.napoleon_enable_type_preprocessor:
+ _type = _convert_numpy_type_spec(
+ _type,
+ location=self._get_location(),
+ translations=self._config.napoleon_type_aliases or {},
+ )
if prefer_type and not _type:
_type, _name = _name, _type
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py
index 7eb908058..06a4a0c1a 100644
--- a/tests/test_ext_napoleon_docstring.py
+++ b/tests/test_ext_napoleon_docstring.py
@@ -1317,6 +1317,27 @@ class NumpyDocstringTest(BaseDocstringTest):
expected = dedent(expected)
self.assertEqual(expected, actual)
+ def test_type_preprocessor(self):
+ docstring = dedent("""
+ Single line summary
+
+ Parameters
+ ----------
+ arg1:str
+ Extended
+ description of arg1
+ """)
+
+ config = Config(napoleon_preprocess_types=False, napoleon_use_param=False)
+ actual = str(NumpyDocstring(docstring, config))
+ expected = dedent("""
+ Single line summary
+
+ :Parameters: **arg1** (*str*) -- Extended
+ description of arg1
+ """)
+ self.assertEqual(expected, actual)
+
def test_parameters_with_class_reference(self):
docstring = """\
Parameters