diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-03 18:52:29 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-04-03 18:52:29 +0200 |
commit | 197043d5aec03e08d769495fd140bf341c331168 (patch) | |
tree | 0148e91e39c964a4678474468442a0c12eede7f6 | |
parent | 634f2132c4998aa198afbff5110d6da803617468 (diff) | |
download | pep8-197043d5aec03e08d769495fd140bf341c331168.tar.gz |
Refactor the logical line building and checking.
-rwxr-xr-x | pep8.py | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -1296,7 +1296,7 @@ class Checker(object): def build_tokens_line(self): """Build a logical line from tokens.""" - self.mapping = [] + mapping = [] logical = [] comments = [] length = 0 @@ -1323,23 +1323,21 @@ class Checker(object): fill = self.lines[end_row - 1][end:start] logical.append(fill) length += len(fill) - self.mapping.append((length, token)) + mapping.append((length, token)) logical.append(text) length += len(text) previous = token self.logical_line = ''.join(logical) self.noqa = comments and noqa(''.join(comments)) - # With Python 2, if the line ends with '\r\r\n' the assertion fails - # assert self.logical_line.strip() == self.logical_line + return mapping or [(0, self.tokens[0])] def check_logical(self): """Build a line from tokens and run all logical checks on it.""" - self.build_tokens_line() self.report.increment_logical_line() - token0 = self.mapping[0][1] if self.mapping else self.tokens[0] - first_line = self.lines[token0[2][0] - 1] - indent = first_line[:token0[2][1]] - self.indent_level = expand_indent(indent) + mapping = self.build_tokens_line() + (start_row, start_col) = mapping[0][1][2] + start_line = self.lines[start_row - 1] + self.indent_level = expand_indent(start_line[:start_col]) if self.verbose >= 2: print(self.logical_line[:80].rstrip()) for name, check, argument_names in self._logical_checks: @@ -1350,8 +1348,7 @@ class Checker(object): if isinstance(offset, tuple): (li_number, li_offset) = offset else: - (token_offset, token) = (0, token0) - for (token_offset, token) in self.mapping: + for (token_offset, token) in mapping: if offset < token_offset: break li_number = token[2][0] |