Skip to content

Commit

Permalink
Suggestions from the review
Browse files Browse the repository at this point in the history
* Docstring
* Check explicitly for maxline
* \n\r preserve
  • Loading branch information
gaogaotiantian committed Apr 18, 2023
1 parent fe5ffd3 commit 14a73a5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,16 @@ def get_docstring(node, clean=True):


_line_pattern = re.compile(r"(.*?(?:\r\n|\n|\r|$))")
def _splitlines_no_ff(source, maxlines=-1):
def _splitlines_no_ff(source, maxlines=None):
"""Split a string into lines ignoring form feed and other chars.
This mimics how the Python parser splits source code.
"""
lines = []
for lineno, match in enumerate(_line_pattern.finditer(source), 1):
if maxlines > 0 and lineno > maxlines:
if maxlines is not None and lineno > maxlines:
break
lines.append(match[0].replace("\r\n", "\n"))
lines.append(match[0])
return lines


Expand Down

0 comments on commit 14a73a5

Please sign in to comment.