Anonymous avatar Anonymous committed e8e4ba4

rename: extracted _is_local()

Comments (0)

Files changed (1)

rope/refactor/rename.py

                 'instead. ', DeprecationWarning, stacklevel=2)
             if in_file:
                 resources = [self.resource]
-        if self._is_renaming_a_function_local_name():
+        if _is_local(self.old_pyname):
             resources = [self.resource]
         if resources is None:
             resources = self.pycore.get_python_files()
         else:
             return resource in resources
 
-    def _is_renaming_a_function_local_name(self):
-        module, lineno = self.old_pyname.get_definition_location()
-        if lineno is None:
-            return False
-        scope = module.get_scope().get_inner_scope_for_line(lineno)
-        if isinstance(self.old_pyname, pynames.DefinedName) and \
-           scope.get_kind() in ('Function', 'Class'):
-            scope = scope.parent
-        return scope.get_kind() == 'Function' and \
-               self.old_pyname in scope.get_names().values() and \
-               isinstance(self.old_pyname, pynames.AssignedName)
-
     def _is_renaming_a_module(self):
         if isinstance(self.old_pyname.get_object(), pyobjects.AbstractModule):
             return True
         if region is None or region[0] <= start < region[1]:
             change_collector.add_change(start, end, new_name)
     return change_collector.get_changed()
+
+def _is_local(pyname):
+    module, lineno = pyname.get_definition_location()
+    if lineno is None:
+        return False
+    scope = module.get_scope().get_inner_scope_for_line(lineno)
+    if isinstance(pyname, pynames.DefinedName) and \
+       scope.get_kind() in ('Function', 'Class'):
+        scope = scope.parent
+    return scope.get_kind() == 'Function' and \
+           pyname in scope.get_names().values() and \
+           isinstance(pyname, pynames.AssignedName)
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.