Refactor splitlines -> split_lines.

This commit is contained in:
Dave Halter
2017-08-15 19:54:21 +02:00
parent 476d5fb0d1
commit ab027885c7
8 changed files with 30 additions and 30 deletions

View File

@@ -3,7 +3,7 @@ import os
from parso._compatibility import FileNotFoundError, is_pypy
from parso.pgen2.pgen import generate_grammar
from parso.utils import splitlines, source_to_unicode, parse_version_string
from parso.utils import split_lines, source_to_unicode, parse_version_string
from parso.python.diff import DiffParser
from parso.python.tokenize import tokenize_lines, tokenize
from parso.cache import parser_cache, load_module, save_module
@@ -88,7 +88,7 @@ class Grammar(object):
code = source_to_unicode(code)
lines = splitlines(code, keepends=True)
lines = split_lines(code, keepends=True)
if diff_cache:
if self._diff_parser is None:
raise TypeError("You have to define a diff parser to be able "

View File

@@ -10,7 +10,7 @@ import difflib
from collections import namedtuple
import logging
from parso.utils import splitlines
from parso.utils import split_lines
from parso.python.parser import Parser
from parso.python.tree import EndMarker
from parso.python.tokenize import (NEWLINE, TokenInfo, ERROR_DEDENT,
@@ -154,7 +154,7 @@ class DiffParser(object):
last_pos = self._module.end_pos[0]
if last_pos != line_length:
current_lines = splitlines(self._module.get_code(), keepends=True)
current_lines = split_lines(self._module.get_code(), keepends=True)
diff = difflib.unified_diff(current_lines, new_lines)
raise Exception(
"There's an issue (%s != %s) with the diff parser. Please report:\n%s"
@@ -572,7 +572,7 @@ class _NodesStack(object):
end_pos = list(last_leaf.end_pos)
except IndexError:
end_pos = [1, 0]
lines = splitlines(self.prefix)
lines = split_lines(self.prefix)
assert len(lines) > 0
if len(lines) == 1:
end_pos[1] += len(lines[0])

View File

@@ -22,7 +22,7 @@ from parso.python.token import (tok_name, N_TOKENS, ENDMARKER, STRING, NUMBER, o
NAME, OP, ERRORTOKEN, NEWLINE, INDENT, DEDENT,
ERROR_DEDENT)
from parso._compatibility import py_version
from parso.utils import splitlines
from parso.utils import split_lines
TokenCollection = namedtuple(
@@ -224,7 +224,7 @@ class TokenInfo(namedtuple('Token', ['type', 'string', 'start_pos', 'prefix'])):
@property
def end_pos(self):
lines = splitlines(self.string)
lines = split_lines(self.string)
if len(lines) > 1:
return self.start_pos[0] + len(lines) - 1, 0
else:
@@ -233,7 +233,7 @@ class TokenInfo(namedtuple('Token', ['type', 'string', 'start_pos', 'prefix'])):
def tokenize(code, version_info):
"""Generate tokens from a the source code (string)."""
lines = splitlines(code, keepends=True)
lines = split_lines(code, keepends=True)
return tokenize_lines(lines, version_info)

View File

@@ -9,9 +9,9 @@ from parso._compatibility import unicode, total_ordering
Version = namedtuple('Version', 'major, minor, micro')
def splitlines(string, keepends=False):
def split_lines(string, keepends=False):
r"""
A splitlines for Python code. In contrast to Python's ``str.splitlines``,
A str.splitlines for Python code. In contrast to Python's ``str.splitlines``,
looks at form feeds and other special characters as normal text. Just
splits ``\n`` and ``\r\n``.
Also different: Returns ``['']`` for an empty string input.