diff options
-rw-r--r-- | doc/usage/extensions/napoleon.rst | 4 | ||||
-rw-r--r-- | sphinx/ext/napoleon/__init__.py | 11 | ||||
-rw-r--r-- | sphinx/ext/napoleon/docstring.py | 3 | ||||
-rw-r--r-- | tests/test_ext_napoleon_docstring.py | 28 |
4 files changed, 38 insertions, 8 deletions
diff --git a/doc/usage/extensions/napoleon.rst b/doc/usage/extensions/napoleon.rst index 504ef015a..dc52e6375 100644 --- a/doc/usage/extensions/napoleon.rst +++ b/doc/usage/extensions/napoleon.rst @@ -409,10 +409,10 @@ sure that "sphinx.ext.napoleon" is enabled in `conf.py`:: .. attribute:: attr1 - *int* - Description of `attr1` + :type: int + .. confval:: napoleon_use_param True to use a ``:param:`` role for each function parameter. False to diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index 80fcd3dcb..00b78e859 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -9,7 +9,7 @@ :license: BSD, see LICENSE for details. """ -import sphinx +from sphinx import __display_version__ as __version__ from sphinx.application import Sphinx from sphinx.ext.napoleon.docstring import GoogleDocstring, NumpyDocstring @@ -172,10 +172,10 @@ class Config: .. attribute:: attr1 - *int* - Description of `attr1` + :type: int + napoleon_use_param : :obj:`bool` (Defaults to True) True to use a ``:param:`` role for each function parameter. False to use a single ``:parameters:`` role for all the parameters. @@ -300,7 +300,8 @@ def setup(app): """ if not isinstance(app, Sphinx): - return # probably called by tests + # probably called by tests + return {'version': __version__, 'parallel_read_safe': True} _patch_python_domain() @@ -310,7 +311,7 @@ def setup(app): for name, (default, rebuild) in Config._config_values.items(): app.add_config_value(name, default, rebuild) - return {'version': sphinx.__display_version__, 'parallel_read_safe': True} + return {'version': __version__, 'parallel_read_safe': True} def _patch_python_domain(): diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 29654683a..35c0b5c46 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -268,8 +268,9 @@ class GoogleDocstring(UnicodeMixin): # type: () -> Tuple[unicode, List[unicode]] line = next(self._line_iter) _type, colon, _desc = self._partition_field_on_colon(line) - if not colon: + if not colon or not _desc: _type, _desc = _desc, _type + _desc += colon _descs = [_desc] + self._dedent(self._consume_to_end()) _descs = self.__class__(_descs, self._config).lines() return _type, _descs diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index e299a5879..2bc7f626c 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -77,6 +77,34 @@ Sample namedtuple subclass self.assertEqual(expected, actual) +class InlineAttributeTest(BaseDocstringTest): + + def test_class_data_member(self): + config = Config() + docstring = """data member description: + +- a: b +""" + actual = str(GoogleDocstring(docstring, config=config, app=None, + what='attribute', name='some_data', obj=0)) + expected = """data member description: + +- a: b""" + + self.assertEqual(expected, actual) + + def test_class_data_member_inline(self): + config = Config() + docstring = """b: data member description with :ref:`reference`""" + actual = str(GoogleDocstring(docstring, config=config, app=None, + what='attribute', name='some_data', obj=0)) + expected = """data member description with :ref:`reference` + +:type: b""" + + self.assertEqual(expected, actual) + + class GoogleDocstringTest(BaseDocstringTest): docstrings = [( """Single line summary""", |