Commits

Anonymous committed 65c0324

Fixed not matching normal vars and attributes

  • Participants
  • Parent commits 140c18a

Comments (0)

Files changed (5)

rope/base/pynames.py

-import rope.base.pyobjects
 import rope.base.oi.objectinfer
 from rope.base.exceptions import (ModuleNotFoundError,
                                   AttributeNotFoundError)

rope/refactor/extract.py

 import re
 
-import rope.base.pyobjects
-from rope.base import ast, builtins, codeanalyze, evaluate
+from rope.base import ast, codeanalyze
 from rope.base.change import ChangeSet, ChangeContents
 from rope.base.exceptions import RefactoringError
 from rope.refactor import sourceutils, similarfinder, patchedast, suites

rope/refactor/similarfinder.py

     def _match_normal_var(self, node1, node2, mapping):
         name = self.ropevar.get_base(node1.id)
         if name not in mapping:
-            if isinstance(node2, ast.Name) and node2.id == name or \
-               isinstance(node2, ast.Attribute) and node2.attr == name:
+            if isinstance(node2, ast.Name) and node2.id == name:
                 mapping[name] = node2
                 return True
             return False

ropetest/refactor/extracttest.py

                    '    def f2(self):\n        print(str(1))\n'
         self.assertEquals(expected, refactored)
 
+    def test_extract_method_when_an_attribute_exists_in_function_scope(self):
+        code = 'class A(object):\n    def func(self):\n        pass\n' \
+               'a = A()\n' \
+               'def f():\n' \
+               '    func = a.func()\n' \
+               '    print func\n'
+
+        start, end = self._convert_line_range_to_offset(code, 6, 6)
+        refactored = self.do_extract_method(code, start, end, 'g')
+        refactored = refactored[refactored.index('A()') + 4:]
+        expected = 'def f():\n    func = g()\n    print func\n\n' \
+                   'def g():\n    func = a.func()\n    return func\n'
+        self.assertEquals(expected, refactored)
+
 
 if __name__ == '__main__':
     unittest.main()

ropetest/refactor/similarfindertest.py

         source = 'x.a = 1\n'
         finder = similarfinder.SimilarFinder(source)
         result = list(finder.get_matches('${a} = 1'))
-        self.assertEquals(1, len(result))
+        self.assertEquals(0, len(result))
 
     def test_functions_not_matching_when_only_first_parameters(self):
         source = 'f(1, 2)\n'