Anonymous avatar Anonymous committed d190167

Moved codeanalyze.ScopeNameFinder.get_pyname_in_scope to evaluate

Comments (0)

Files changed (3)

rope/base/codeanalyze.py

             module_pyname = self._find_module(module)
             return (None, module_pyname)
         name = self.word_finder.get_primary_at(offset)
-        return self.get_primary_and_pyname_in_scope(holding_scope, name)
+        return evaluate.get_primary_and_pyname_in_scope(holding_scope, name)
 
     def get_enclosing_function(self, offset):
         function_parens = self.word_finder.find_parens_start_from_inside(offset)
         try:
             function_pyname = self.get_pyname_at(function_parens - 1)
-        except BadIdentifierError:
+        except evaluate.BadIdentifierError:
             function_pyname = None
         if function_pyname is not None:
             pyobject = function_pyname.get_object()
         return rope.base.pynames.ImportedModule(
             self.module_scope.pyobject, module_name[dot_count:], dot_count)
 
-    @staticmethod
-    def get_pyname_in_scope(holding_scope, name):
-        return ScopeNameFinder.get_primary_and_pyname_in_scope(
-            holding_scope, name)[1]
-
-    # XXX: This might belong to `rope.base.evaluate` module
-    @staticmethod
-    def get_primary_and_pyname_in_scope(holding_scope, name):
-        try:
-            # parenthesizing for handling cases like 'a_var.\nattr'
-            node = ast.parse('(%s)' % name)
-        except SyntaxError:
-            raise BadIdentifierError('Not a resolvable python identifier selected.')
-        return evaluate.get_primary_and_result(holding_scope, node)
-
-
-class BadIdentifierError(rope.base.exceptions.RopeError):
-    pass
-
 
 def get_pyname_at(pycore, resource, offset):
     """Finds the pyname at the offset

rope/base/evaluate.py

 from rope.base import ast, exceptions
 
 
+class BadIdentifierError(rope.base.exceptions.RopeError):
+    pass
+
+
 class StatementEvaluator(object):
 
     def __init__(self, scope):
     return evaluator.result
 
 
+def get_pyname_in_scope(holding_scope, name):
+    return get_primary_and_pyname_in_scope(holding_scope, name)[1]
+
+
+def get_primary_and_pyname_in_scope(holding_scope, name):
+    try:
+        # parenthesizing for handling cases like 'a_var.\nattr'
+        node = ast.parse('(%s)' % name)
+    except SyntaxError:
+        raise BadIdentifierError('Not a resolvable python identifier selected.')
+    return get_primary_and_result(holding_scope, node)
+
+
 class Arguments(object):
     """A class for evaluating parameters passed to a function
 

rope/contrib/codeassist.py

 
 import rope.base.codeanalyze
 from rope.base import pyobjects, pynames, taskhandle, builtins, exceptions
-from rope.base.codeanalyze import (ArrayLinesAdapter, BadIdentifierError,
-                                   LogicalLineFinder, ScopeNameFinder,
+from rope.base.codeanalyze import (ArrayLinesAdapter, LogicalLineFinder,
+                                   ScopeNameFinder,
                                    SourceLinesAdapter, WordRangeFinder)
 from rope.refactor import occurrences, functionutils
 
     def _dotted_completions(self, module_scope, holding_scope):
         result = {}
         pyname_finder = ScopeNameFinder(module_scope.pyobject)
-        found_pyname = pyname_finder.get_pyname_in_scope(holding_scope,
-                                                         self.expression)
+        found_pyname = rope.base.evaluate.get_pyname_in_scope(
+            holding_scope, self.expression)
         if found_pyname is not None:
             element = found_pyname.get_object()
             for name, pyname in element.get_attributes().items():
                 find_parens_start_from_inside(offset - 1, stop)
             primary = word_finder.get_primary_at(function_parens - 1)
             try:
-                function_pyname = ScopeNameFinder.\
+                function_pyname = rope.base.evaluate.\
                     get_pyname_in_scope(scope, primary)
-            except BadIdentifierError, e:
+            except rope.base.evaluate.BadIdentifierError, e:
                 return {}
             if function_pyname is not None:
                 pyobject = function_pyname.get_object()
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.