Skip to content

Commit 54e3cb0

Browse files
authored
Merge pull request #207 from pvanmulbregt/seealso2
ENH: Allow a trailing COMMA or PERIOD in a See Also function list block
2 parents af6690a + 9d64203 commit 54e3cb0

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

numpydoc/docscrape.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _parse_param_list(self, content, single_element_is_type=False):
245245
#
246246
# <FUNCNAME>
247247
# <FUNCNAME> SPACE* COLON SPACE+ <DESC> SPACE*
248-
# <FUNCNAME> ( COMMA SPACE+ <FUNCNAME>)* SPACE*
248+
# <FUNCNAME> ( COMMA SPACE+ <FUNCNAME>)+ (COMMA | PERIOD)? SPACE*
249249
# <FUNCNAME> ( COMMA SPACE+ <FUNCNAME>)* SPACE* COLON SPACE+ <DESC> SPACE*
250250

251251
# <FUNCNAME> is one of
@@ -258,8 +258,8 @@ def _parse_param_list(self, content, single_element_is_type=False):
258258
# <DESC> is a string describing the function.
259259

260260
_role = r":(?P<role>\w+):"
261-
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`"
262-
_funcplain = r"(?P<name2>[a-zA-Z0-9_.-]+)"
261+
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_\.-]+)`"
262+
_funcplain = r"(?P<name2>[a-zA-Z0-9_\.-]+)"
263263
_funcname = r"(" + _role + _funcbacktick + r"|" + _funcplain + r")"
264264
_funcnamenext = _funcname.replace('role', 'rolenext')
265265
_funcnamenext = _funcnamenext.replace('name', 'namenext')
@@ -271,7 +271,7 @@ def _parse_param_list(self, content, single_element_is_type=False):
271271
_funcname +
272272
r"(?P<morefuncs>([,]\s+" + _funcnamenext + r")*)" +
273273
r")" + # end of "allfuncs"
274-
r"(?P<trailing>\s*,)?" + # Some function lists have a trailing comma
274+
r"(?P<trailing>[,\.])?" + # Some function lists have a trailing comma (or period) '\s*'
275275
_description)
276276

277277
# Empty <DESC> elements are replaced with '..'
@@ -306,9 +306,9 @@ def parse_item_name(text):
306306
description = None
307307
if line_match:
308308
description = line_match.group('desc')
309-
if line_match.group('trailing'):
309+
if line_match.group('trailing') and description:
310310
self._error_location(
311-
'Unexpected comma after function list at index %d of '
311+
'Unexpected comma or period after function list at index %d of '
312312
'line "%s"' % (line_match.end('trailing'), line),
313313
error=False)
314314
if not description and line.startswith(' '):

numpydoc/tests/test_docscrape.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from numpydoc.docscrape_sphinx import (SphinxDocString, SphinxClassDoc,
1818
SphinxFunctionDoc, get_doc_object)
1919
from pytest import raises as assert_raises
20+
from pytest import warns as assert_warns
2021

2122

2223
if sys.version_info[0] >= 3:
@@ -859,6 +860,21 @@ class Dummy(object):
859860
assert(':func:`func_d`' in s)
860861

861862

863+
def test_see_also_trailing_comma_warning():
864+
warnings.filterwarnings('error')
865+
with assert_warns(Warning, match='Unexpected comma or period after function list at index 43 of line .*'):
866+
doc6 = NumpyDocString(
867+
"""
868+
z(x,theta)
869+
870+
See Also
871+
--------
872+
func_f2, func_g2, :meth:`func_h2`, func_j2, : description of multiple
873+
:class:`class_j`: fubar
874+
foobar
875+
""")
876+
877+
862878
def test_unknown_section():
863879
doc_text = """
864880
Test having an unknown section

0 commit comments

Comments
 (0)