Commits

Aviv Ben-Yosef committed 7c1afff

Fixing bug in arguments given to extracted method.

  • Participants
  • Parent commits f5c2fc6

Comments (0)

Files changed (2)

File rope/refactor/extract.py

         if not self.info.one_line:
             result = (self.info_collector.prewritten &
                       self.info_collector.read)
-            result |= (self.info_collector.maybe_written &
-                       self.info_collector.postread)
+            result |= (self.info_collector.prewritten &
+                       self.info_collector.postread &
+                       (self.info_collector.maybe_written -
+                        self.info_collector.written))
             return list(result)
         start = self.info.region[0]
         if start == self.info.lines_region[0]:

File ropetest/refactor/extracttest.py

                    '    return a\n'
         self.assertEquals(expected, refactored)
 
+    def test_extract_method_with_variables_possibly_written_to(self):
+        code = "def a_func(b):\n" \
+               "    if b > 0:\n" \
+               "        a = 2\n" \
+               "    print a\n"
+        start, end = self._convert_line_range_to_offset(code, 2, 3)
+        refactored = self.do_extract_method(code, start, end, 'extracted')
+        expected = "def a_func(b):\n" \
+                   "    a = extracted(b)\n" \
+                   "    print a\n\n" \
+                   "def extracted(b):\n" \
+                   "    if b > 0:\n" \
+                   "        a = 2\n" \
+                   "    return a\n"
+        self.assertEquals(expected, refactored)
 
 if __name__ == '__main__':
     unittest.main()