Anonymous avatar Anonymous committed 86826f5

added astutils.py

Comments (0)

Files changed (4)

rope/base/astutils.py

+from rope.base import ast
+
+
+def get_name_levels(node):
+    visitor = _NodeNameCollector()
+    ast.walk(node, visitor)
+    return visitor.names
+
+
+class _NodeNameCollector(object):
+
+    def __init__(self, levels=None):
+        self.names = []
+        self.levels = levels
+        self.index = 0
+
+    def _add_node(self, node):
+        new_levels = []
+        if self.levels is not None:
+            new_levels = list(self.levels)
+            new_levels.append(self.index)
+        self.index += 1
+        self._added(node, new_levels)
+
+    def _added(self, node, levels):
+        if hasattr(node, 'id'):
+            self.names.append((node.id, levels))
+
+    def _Name(self, node):
+        self._add_node(node)
+
+    def _Tuple(self, node):
+        new_levels = []
+        if self.levels is not None:
+            new_levels = list(self.levels)
+            new_levels.append(self.index)
+        self.index += 1
+        visitor = _NodeNameCollector(new_levels)
+        for child in ast.get_child_nodes(node):
+            ast.walk(child, visitor)
+        self.names.extend(visitor.names)
+
+    def _Subscript(self, node):
+        self._add_node(node)

rope/base/defpyobjects.py

 import rope.base.evaluate
 import rope.base.oi.objectinfer
 import rope.base.pyscopes
-from rope.base import defpynames as pynames, exceptions, ast, pyobjects
+from rope.base import (defpynames as pynames, exceptions,
+                       ast, astutils, pyobjects)
 from rope.base.pyobjects import *
 
 
         self._assigned(node.id, assignment)
 
     def _Tuple(self, node):
-        names = rope.base.evaluate._get_name_levels(node)
+        names = astutils.get_name_levels(node)
         for name, levels in names:
             assignment = None
             if self.assigned_ast is not None:

rope/base/evaluate.py

 import rope.base.pynames
 import rope.base.exceptions
 import rope.base.pyobjects
-from rope.base import ast, exceptions
+from rope.base import ast, astutils, exceptions
 
 
 class BadIdentifierError(rope.base.exceptions.RopeError):
     things like lineno, evaluation, and module.
     """
     result = {}
-    names = _get_name_levels(targets)
+    names = astutils.get_name_levels(targets)
     for name, levels in names:
         assignment = rope.base.pynames._Assigned(assigned, levels)
         result[name] = EvaluatedName(assignment=assignment, **kwds)
     def invalidate(self):
         """Forget the `PyObject` this `PyName` holds"""
         self.pyobject.set(None)
-
-
-def _get_name_levels(node):
-    visitor = _NodeNameCollector()
-    ast.walk(node, visitor)
-    return visitor.names
-
-
-class _NodeNameCollector(object):
-
-    def __init__(self, levels=None):
-        self.names = []
-        self.levels = levels
-        self.index = 0
-
-    def _add_node(self, node):
-        new_levels = []
-        if self.levels is not None:
-            new_levels = list(self.levels)
-            new_levels.append(self.index)
-        self.index += 1
-        self._added(node, new_levels)
-
-    def _added(self, node, levels):
-        if hasattr(node, 'id'):
-            self.names.append((node.id, levels))
-
-    def _Name(self, node):
-        self._add_node(node)
-
-    def _Tuple(self, node):
-        new_levels = []
-        if self.levels is not None:
-            new_levels = list(self.levels)
-            new_levels.append(self.index)
-        self.index += 1
-        visitor = _NodeNameCollector(new_levels)
-        for child in ast.get_child_nodes(node):
-            ast.walk(child, visitor)
-        self.names.extend(visitor.names)
-
-    def _Subscript(self, node):
-        self._add_node(node)

rope/base/oi/staticoi.py

 import rope.base.ast
-from rope.base import pyobjects, evaluate
+from rope.base import pyobjects, evaluate, astutils
 
 
 def analyze_module(pycore, pymodule, should_analyze, search_subscopes):
                 # IDEA: handle `__setslice__`, too
 
 
-class _SOIAssignVisitor(evaluate._NodeNameCollector):
+class _SOIAssignVisitor(astutils._NodeNameCollector):
 
     def __init__(self):
         super(_SOIAssignVisitor, self).__init__()
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.