diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 1e32788a0..146ea66ae 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -148,6 +148,7 @@ class GoogleDocstring(UnicodeMixin): 'warning': self._parse_warning_section, 'warnings': self._parse_warning_section, 'warns': self._parse_warns_section, + 'yield': self._parse_yields_section, 'yields': self._parse_yields_section, } self._parse() @@ -590,7 +591,7 @@ class GoogleDocstring(UnicodeMixin): return self._format_fields('Warns', self._consume_fields()) def _parse_yields_section(self, section): - fields = self._consume_fields(prefer_type=True) + fields = self._consume_returns_section() return self._format_fields('Yields', fields) def _strip_empty(self, lines): diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 6e19b3279..0271391a5 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -222,6 +222,33 @@ class GoogleDocstringTest(BaseDocstringTest): Variable length argument list. * **\\*\\*kwargs** -- Arbitrary keyword arguments.""" + ), ( + """ + Single line summary + + Yield: + str:Extended + description of yielded value + """, + """ + Single line summary + + :Yields: *str* -- + Extended + description of yielded value""" + ), ( + """ + Single line summary + + Yields: + Extended + description of yielded value + """, + """ + Single line summary + + :Yields: Extended + description of yielded value""" )] def test_docstrings(self): @@ -424,7 +451,39 @@ class NumpyDocstringTest(BaseDocstringTest): Variable length argument list. * ****kwargs** -- Arbitrary keyword arguments.""" - )] + ), ( + """ + Single line summary + + Yield + ----- + str + Extended + description of yielded value + """, + """ + Single line summary + + :Yields: *str* -- + Extended + description of yielded value""" + ), ( + """ + Single line summary + + Yields + ------ + str + Extended + description of yielded value + """, + """ + Single line summary + + :Yields: *str* -- + Extended + description of yielded value""" + )] def test_docstrings(self): config = Config(napoleon_use_param=False, napoleon_use_rtype=False)