Skip to content

Commit d99ef90

Browse files
committed
Merge pull request #40 from larsmans/parse-errors
ENH: better error messages from NumpyDocString
2 parents ede5cd6 + 1a84833 commit d99ef90

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

numpydoc/docscrape.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ def is_empty(self):
8888
return not ''.join(self._str).strip()
8989

9090

91+
class ParseError(Exception):
92+
def __str__(self):
93+
message = self.message
94+
if hasattr(self, 'docstring'):
95+
message = "%s in %r" % (message, self.docstring)
96+
return message
97+
98+
9199
class NumpyDocString(collections.Mapping):
92100
def __init__(self, docstring, config={}):
101+
orig_docstring = docstring
93102
docstring = textwrap.dedent(docstring).split('\n')
94103

95104
self._doc = Reader(docstring)
@@ -113,7 +122,11 @@ def __init__(self, docstring, config={}):
113122
'index': {}
114123
}
115124

116-
self._parse()
125+
try:
126+
self._parse()
127+
except ParseError as e:
128+
e.docstring = orig_docstring
129+
raise
117130

118131
def __getitem__(self, key):
119132
return self._parsed_data[key]
@@ -219,7 +232,7 @@ def parse_item_name(text):
219232
return g[3], None
220233
else:
221234
return g[2], g[1]
222-
raise ValueError("%s is not a item name" % text)
235+
raise ParseError("%s is not a item name" % text)
223236

224237
def push_item(name, rest):
225238
if not name:

0 commit comments

Comments
 (0)