Anonymous avatar Anonymous committed 03827ad

finding Scope.end for one-liners

Comments (0)

Files changed (2)


         if not scope.parent:
             return self.lines.length()
         end = scope.pyobject.get_ast().body[-1].lineno
-        body_indents = self._get_body_indents(scope)
+        if end == scope.start:
+            # handling one-liners
+            body_indents = self._get_scope_indents(scope) + 4
+        else:
+            body_indents = self._get_body_indents(scope)
         for l in self.logical_lines.generate_starts(
             min(end + 1, self.lines.length()), self.lines.length() + 1):
             if not self._is_empty_line(l):


         name_finder = rope.base.evaluate.ScopeNameFinder(pymod)
+    def test_one_liners(self):
+        code = 'var = 1\ndef f(): var = 2\nprint var\n'
+        pymod = self.pycore.get_string_module(code)
+        name_finder = rope.base.evaluate.ScopeNameFinder(pymod)
+        pyname = name_finder.get_pyname_at(code.rindex('var'))
+        self.assertEquals(pymod.get_attribute('var'), pyname)
 class LogicalLineFinderTest(unittest.TestCase):
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
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.