Skip to content

Commit 1d21eb1

Browse files
committed
Line offsets
1 parent 701fc3d commit 1d21eb1

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

numpydoc/docscrape.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def _strip(self, doc):
173173

174174
return doc[i:len(doc)-j]
175175

176+
def _get_line_no(self):
177+
return self._doc._l
178+
176179
def _read_to_next_section(self):
177180
section = self._doc.read_to_next_empty_line()
178181

@@ -186,20 +189,22 @@ def _read_to_next_section(self):
186189

187190
def _read_sections(self):
188191
while not self._doc.eof():
192+
start = self._get_line_no()
189193
data = self._read_to_next_section()
190194
name = data[0].strip()
191195

192196
if name.startswith('..'): # index section
193-
yield name, data[1:]
197+
yield name, data[1:], (start, len(data))
194198
elif len(data) < 2:
195199
yield StopIteration
196200
else:
197-
yield name, self._strip(data[2:])
201+
yield name, self._strip(data[2:]), (start, len(data))
198202

199203
def _parse_param_list(self, content):
200204
r = Reader(content)
201205
params = []
202206
while not r.eof():
207+
start = r._l
203208
header = r.read().strip()
204209
if ' : ' in header:
205210
arg_name, arg_type = header.split(' : ')[:2]
@@ -209,7 +214,7 @@ def _parse_param_list(self, content):
209214
desc = r.read_to_next_unindented_line()
210215
desc = dedent_lines(desc)
211216

212-
params.append((arg_name, arg_type, desc))
217+
params.append((arg_name, arg_type, desc, (start, len(desc) + 1)))
213218

214219
return params
215220

@@ -315,9 +320,10 @@ def _parse_summary(self):
315320
def _parse(self):
316321
self._doc.reset()
317322
self._parse_summary()
323+
self._line_spans = {}
318324

319325
sections = list(self._read_sections())
320-
section_names = set([section for section, content in sections])
326+
section_names = set([section for section, content, span in sections])
321327

322328
has_returns = 'Returns' in section_names
323329
has_yields = 'Yields' in section_names
@@ -326,7 +332,7 @@ def _parse(self):
326332
msg = 'Docstring contains both a Returns and Yields section.'
327333
raise ValueError(msg)
328334

329-
for (section, content) in sections:
335+
for (section, content, span) in sections:
330336
if not section.startswith('..'):
331337
section = (s.capitalize() for s in section.split(' '))
332338
section = ' '.join(section)
@@ -335,10 +341,19 @@ def _parse(self):
335341
section)
336342
raise ValueError(msg)
337343

344+
self._line_spans[section] = span
345+
section_start = span[0] + 2
346+
338347
if section in ('Parameters', 'Returns', 'Yields', 'Raises',
339348
'Warns', 'Other Parameters', 'Attributes',
340349
'Methods'):
341-
self[section] = self._parse_param_list(content)
350+
param_list = []
351+
for i, param in enumerate(self._parse_param_list(content)):
352+
span = param[-1]
353+
span = (span[0] + section_start, span[1])
354+
self._line_spans[section, i] = span
355+
param_list.append(param[:-1])
356+
self[section] = param_list
342357
elif section.startswith('.. index::'):
343358
self['index'] = self._parse_index(section, content)
344359
elif section == 'See Also':

0 commit comments

Comments
 (0)