Skip to content

Commit

Permalink
Make numpy doc parsing more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
jakevdp committed Apr 1, 2021
1 parent 8691244 commit d6ccaca
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions jax/_src/numpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ def _parse_numpydoc(docstr: Optional[str]) -> ParsedDoc:
if docstr is None or not docstr.strip():
return ParsedDoc(docstr)

firstline, _, body = docstr.partition('\n')
signature, body = "", docstr
match = _numpy_signature_re.match(body)
if match:
signature = match.group()
body = docstr[match.end():]

firstline, _, body = body.partition('\n')
body = textwrap.dedent(body.lstrip('\n'))

signature = ""
if _numpy_signature_re.match(firstline):
signature, firstline = firstline, ""
else:
match = _numpy_signature_re.match(body)
if match:
signature = match.group()
body = body[match.end():]
match = _numpy_signature_re.match(body)
if match:
signature = match.group()
body = body[match.end():]

summary = firstline
if not summary:
Expand Down

0 comments on commit d6ccaca

Please sign in to comment.