Commits

Ali Gholami Rudi  committed dbae61f

inlining one-line functions with line breaks

  • Participants
  • Parent commits 1853630

Comments (0)

Files changed (2)

File rope/refactor/sourceutils.py

     elif len(node.body) > 1:
         start_line = node.body[1].lineno
     start = lines.get_line_start(start_line)
-    if scope.start == start_line:
+    scope_start = pymodule.logical_lines.logical_line_in(scope.start)
+    if scope_start[1] >= start_line:
         # a one-liner!
-        # XXX: one-liners with line breaks
+        # XXX: what if colon appears in a string
         start = pymodule.source_code.index(':', start) + 1
         while pymodule.source_code[start].isspace():
             start += 1

File ropetest/refactor/inlinetest.py

         refactored = self._inline(code, code.rindex('f'))
         self.assertEquals('var = 1\n', refactored)
 
+    def test_inlining_one_line_functions_with_breaks(self):
+        code = 'def f(\n): return 1\nvar = f()\n'
+        refactored = self._inline(code, code.rindex('f'))
+        self.assertEquals('var = 1\n', refactored)
+
 
 def suite():
     result = unittest.TestSuite()