Skip to content

Commit b618d52

Browse files
committed
ENH: Raise exception if docstring contains Returns and Yields.
1 parent ddd7dc6 commit b618d52

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

numpydoc/docscrape.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,17 @@ def _parse(self):
289289
self._doc.reset()
290290
self._parse_summary()
291291

292-
for (section,content) in self._read_sections():
292+
sections = list(self._read_sections())
293+
section_names = set([section for section, content in sections])
294+
295+
has_returns = 'Returns' in section_names
296+
has_yields = 'Yields' in section_names
297+
# We could do more tests, but we are not. Arbitrarily.
298+
if has_returns and has_yields:
299+
msg = 'Docstring contains both a Returns and Yields section.'
300+
raise ValueError(msg)
301+
302+
for (section, content) in sections:
293303
if not section.startswith('..'):
294304
section = ' '.join([s.capitalize() for s in section.split(' ')])
295305
if section in ('Parameters', 'Returns', 'Yields', 'Raises',

0 commit comments

Comments
 (0)