Skip to content

Commit ba33a0f

Browse files
committed
ENH: Better warning for sections.
1) if the number of -/= is too short/ too long warn, Especially too short it won't be detected as a section. 2) for duplicate section print the docstring to figure out where the problem is.
1 parent b4c5fd1 commit ba33a0f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

numpydoc/docscrape.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def _is_at_section(self):
176176
return True
177177

178178
l2 = self._doc.peek(1).strip() # ---------- or ==========
179+
if len(l2) >= 3 and (set(l2) in ({'-'}, {'='}) ) and len(l2) != len(l1):
180+
snip = '\n'.join(self._doc._str[:2])+'...'
181+
self._error_location(f"potentially wrong underline length... \n{l1} \n{l2} in \n{snip}",
182+
error=False)
179183
return l2.startswith('-'*len(l1)) or l2.startswith('='*len(l1))
180184

181185
def _strip(self, doc):
@@ -387,8 +391,8 @@ def _parse(self):
387391
section = (s.capitalize() for s in section.split(' '))
388392
section = ' '.join(section)
389393
if self.get(section):
390-
self._error_location("The section %s appears twice"
391-
% section)
394+
self._error_location("The section %s appears twice in %s"
395+
% (section, '\n'.join(self._doc._str)))
392396

393397
if section in ('Parameters', 'Other Parameters', 'Attributes',
394398
'Methods'):

0 commit comments

Comments
 (0)