diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index 359e6539..8acc54cf 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -91,7 +91,7 @@ def is_empty(self): class ParseError(Exception): def __str__(self): - message = self.message + message = self.args[0] if hasattr(self, 'docstring'): message = "%s in %r" % (message, self.docstring) return message diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index a7ebdb0b..f52271b7 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -6,7 +6,12 @@ import jinja2 -from numpydoc.docscrape import NumpyDocString, FunctionDoc, ClassDoc +from numpydoc.docscrape import ( + NumpyDocString, + FunctionDoc, + ClassDoc, + ParseError +) from numpydoc.docscrape_sphinx import SphinxDocString, SphinxClassDoc from nose.tools import * @@ -635,6 +640,23 @@ def test_see_also(): elif func == 'class_j': assert desc == ['fubar', 'foobar'] + +def test_see_also_parse_error(): + text = ( + """ + z(x,theta) + + See Also + -------- + :func:`~foo` + """) + with assert_raises(ParseError) as err: + NumpyDocString(text) + assert_equal( + str(r":func:`~foo` is not a item name in '\n z(x,theta)\n\n See Also\n --------\n :func:`~foo`\n '"), + str(err.exception) + ) + def test_see_also_print(): class Dummy(object): """