From 71b8fe8854049f0b88f9bd2aa45848626d6d30b4 Mon Sep 17 00:00:00 2001 From: Rob Ruana Date: Fri, 13 Jun 2014 14:06:39 -0600 Subject: [PATCH] Closes #1489: Removes use of ":annotation:" for attribute types in napoleon, as inline markup is not allowed --- doc/ext/napoleon.rst | 3 ++- sphinx/ext/napoleon/__init__.py | 3 ++- sphinx/ext/napoleon/docstring.py | 6 +++++- tests/test_napoleon_docstring.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/doc/ext/napoleon.rst b/doc/ext/napoleon.rst index 7248e4912..26d494dbf 100644 --- a/doc/ext/napoleon.rst +++ b/doc/ext/napoleon.rst @@ -324,7 +324,8 @@ enabled in `conf.py`:: **If False**:: .. attribute:: attr1 - :annotation: int + + *int* Description of `attr1` diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index b67ea79c0..655a07a05 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -151,7 +151,8 @@ class Config(object): **If False**:: .. attribute:: attr1 - :annotation: int + + *int* Description of `attr1` diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 1a8d88c6a..19f5f395a 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -428,7 +428,11 @@ class GoogleDocstring(UnicodeMixin): else: lines.append('.. attribute:: ' + _name) if _type: - lines.append(' :annotation: ' + _type) + lines.append('') + if '`' in _type: + lines.append(' %s' % _type) + else: + lines.append(' *%s*' % _type) if _desc: lines.extend([''] + self._indent(_desc, 3)) lines.append('') diff --git a/tests/test_napoleon_docstring.py b/tests/test_napoleon_docstring.py index 34ba4e418..b731072a2 100644 --- a/tests/test_napoleon_docstring.py +++ b/tests/test_napoleon_docstring.py @@ -205,6 +205,37 @@ This class should only be used by runtimes. """ self.assertEqual(expected, actual) + def test_attributes_with_class_reference(self): + docstring = """\ +Attributes: + in_attr(:class:`numpy.ndarray`): super-dooper attribute +""" + + actual = str(GoogleDocstring(docstring)) + expected = """\ +.. attribute:: in_attr + + :class:`numpy.ndarray` + + super-dooper attribute +""" + self.assertEqual(expected, actual) + + docstring = """\ +Attributes: + in_attr(numpy.ndarray): super-dooper attribute +""" + + actual = str(GoogleDocstring(docstring)) + expected = """\ +.. attribute:: in_attr + + *numpy.ndarray* + + super-dooper attribute +""" + self.assertEqual(expected, actual) + class NumpyDocstringTest(BaseDocstringTest): docstrings = [(