Aviv Ben-Yosef avatar Aviv Ben-Yosef committed 7c1afff

Fixing bug in arguments given to extracted method.

Comments (0)

Files changed (2)

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]:

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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.