Commits

Anonymous committed 9f963d1

codeanalyze: fixed LogicalLineFinder for end of file continuations

Reported by Sebastjan Trepca.

  • Participants
  • Parent commits 1b77da2

Comments (0)

Files changed (2)

File rope/base/codeanalyze.py

                 while True:
                     line = self.lines.get_line(i)
                     self._analyze_line(line)
-                    if not (self.continuation 
-                            or self.open_count or self.in_string):
+                    if not (self.continuation or self.open_count or
+                            self.in_string) or i == size:
                         break
                     i += 1
                 self._ends[i] = True
                 last_end = end + 1
         except tokenize.TokenError, e:
             current = e.args[1][0]
-            return (last_end, current)
+            return (last_end, max(last_end, current - 1))
         return (last_end, None)
 
     def _logical_lines(self, readline):

File ropetest/codeanalyzetest.py

         line_finder = self._logical_finder(code)
         self.assertEquals((3, 3), line_finder.logical_line_in(3))
 
+    def test_logical_lines_for_lines_with_wrong_continues(self):
+        code = 'var = 1 + \\'
+        line_finder = self._logical_finder(code)
+        self.assertEquals((1, 1), line_finder.logical_line_in(1))
+
     def test_generating_line_starts(self):
         code = 'a = 1\na = 2\n\na = 3\n'
         line_finder = self._logical_finder(code)