Commits

Anonymous committed b367c70

Deprecated LogicalLineFinder.get_logical_line_in()

Use Deprecated LogicalLineFinder.logical_line_in() instead

Comments (0)

Files changed (9)

rope/base/codeanalyze.py

             self._starts[start] = True
             self._ends[end] = True
 
-    def get_logical_line_in(self, line_number):
+    def logical_line_in(self, line_number):
         start = line_number
         while start > 0 and not self.starts[start]:
             start -= 1
     def __init__(self, lines):
         self.lines = lines
 
-    def get_logical_line_in(self, line_number):
+    def logical_line_in(self, line_number):
         indents = count_line_indents(self.lines.get_line(line_number))
         tries = 0
         while True:
                 lineno = e.lineno + block_start - 1
                 indents = count_line_indents(self.lines.get_line(lineno))
 
+    def get_logical_line_in(self, line_number):
+        warnings.warn('Use `LogicalLineFinder.logical_line_in()` instead',
+                      DeprecationWarning, stacklevel=2)
+        return self.logical_line_in(line_number)
+
     def generate_starts(self, start_line=1, end_line=None):
         for start, end in self.logical_lines(start_line, end_line):
             yield start

rope/contrib/codeassist.py

         word_finder = WordRangeFinder(self.code)
         lines = SourceLinesAdapter(self.code)
         lineno = lines.get_line_number(offset)
-        stop_line = LogicalLineFinder(lines).get_logical_line_in(lineno)[0]
+        stop_line = LogicalLineFinder(lines).logical_line_in(lineno)[0]
         stop = lines.get_line_start(stop_line)
         if word_finder.is_on_function_call_keyword(offset - 1, stop):
             name_finder = ScopeNameFinder(pymodule)
     if check_prev:
         prev = lineno - 1
         while prev > 0:
-            start, end = logical_finder.get_logical_line_in(prev)
+            start, end = logical_finder.logical_line_in(prev)
             if end is None or start <= lineno < end:
                 return start
             if start <= prev:
                 break
             prev -= 1
-    return logical_finder.get_logical_line_in(lineno)[0]
+    return logical_finder.logical_line_in(lineno)[0]
 
 
 class PyDocExtractor(object):

rope/contrib/generate.py

         if self.goal_scope == self.source_scope:
             line_finder = self.goal_pymodule.logical_lines
             lineno = lines.get_line_number(self.offset)
-            lineno = line_finder.get_logical_line_in(lineno)[0]
+            lineno = line_finder.logical_line_in(lineno)[0]
             root = suites.ast_suite_tree(self.goal_scope.pyobject.get_ast())
             suite = root.find_suite(lineno)
             indents = sourceutils.get_indents(lines, lineno)

rope/refactor/encapsulate_field.py

                     result.append(self.setter + '(' + var_name + ' %s ' % assignment_type[:-1])
                 current_line = self.lines.get_line_number(start)
                 start_line, end_line = self.pymodule.logical_lines.\
-                                       get_logical_line_in(current_line)
+                                       logical_line_in(current_line)
                 self.last_set = self.lines.get_line_end(end_line)
                 end = self.source.index('=', end) + 1
                 self.set_index = len(result)
         offset = occurance.get_word_range()[0]
         lineno = self.lines.get_line_number(offset)
         start_line, end_line = self.pymodule.logical_lines.\
-                               get_logical_line_in(lineno)
+                               logical_line_in(lineno)
         start_offset = self.lines.get_line_start(start_line)
 
         line = self.source[start_offset:self.lines.get_line_end(end_line)]

rope/refactor/extract.py

         self.region = (self._choose_closest_line_end(start),
                        self._choose_closest_line_end(end, end=True))
 
-        start = self.logical_lines.get_logical_line_in(
+        start = self.logical_lines.logical_line_in(
             self.lines.get_line_number(self.region[0]))[0]
-        end = self.logical_lines.get_logical_line_in(
+        end = self.logical_lines.logical_line_in(
             self.lines.get_line_number(self.region[1]))[1]
         self.region_lines = (start, end)
 
     @property
     def one_line(self):
         return self.region != self.lines_region and \
-               (self.logical_lines.get_logical_line_in(self.region_lines[0]) ==
-                self.logical_lines.get_logical_line_in(self.region_lines[1]))
+               (self.logical_lines.logical_line_in(self.region_lines[0]) ==
+                self.logical_lines.logical_line_in(self.region_lines[1]))
 
     @property
     def global_(self):
         for match in collector.matches:
             start = self.info.lines.get_line_number(match.get_region()[0])
             start_line = self.info.logical_lines.\
-                         get_logical_line_in(start)[0]
+                         logical_line_in(start)[0]
             matched_lines.append(start_line)
         location_finder = _DefinitionLocationFinder(self.info, matched_lines)
         collector.definition_location = (location_finder.find_lineno(),

rope/refactor/inline.py

             if hasattr(decorators[0], 'lineno'):
                 start_line = decorators[0].lineno
         start_offset = lines.get_line_start(start_line)
-        end_line = logicals.get_logical_line_in(scope.get_end())[1]
+        end_line = logicals.logical_line_in(scope.get_end())[1]
         end_offset = min(lines.get_line_end(end_line) + 1,
                          len(self.pymodule.source_code))
         return (start_offset, end_offset)
         logical = self.pymodule.logical_lines
         start_line = scope.get_start()
         start, end = self._get_scope_range()
-        end_line = logical.get_logical_line_in(scope.get_end())[1]
+        end_line = logical.logical_line_in(scope.get_end())[1]
         for i in range(end_line + 1, lines.length()):
             if lines.get_line(i).strip() == '':
                 end_line = i
         lines = codeanalyze.SourceLinesAdapter(source)
         lineno = lines.get_line_number(offset)
         logical_lines = codeanalyze.LogicalLineFinder(lines)
-        lineno = logical_lines.get_logical_line_in(lineno)[1]
+        lineno = logical_lines.logical_line_in(lineno)[1]
         if source[lines.get_line_end(lineno):len(source)].strip() != '':
             raise rope.base.exceptions.RefactoringError(
                 'Cannot inline functions with statements after return statement.')
         end_parens = self._find_end_parens(self.source, end - 1)
         lineno = self.lines.get_line_number(start)
         start_line, end_line = self.pymodule.logical_lines.\
-                               get_logical_line_in(lineno)
+                               logical_line_in(lineno)
         line_start = self.lines.get_line_start(start_line)
         line_end = self.lines.get_line_end(end_line)
         returns = self.source[line_start:start].strip() != '' or \
     definition_line = assignment.ast_node.lineno
     lines = pymodule.lines
     logicals = pymodule.logical_lines
-    start, end = logicals.get_logical_line_in(definition_line)
+    start, end = logicals.logical_line_in(definition_line)
     definition_with_assignment = _join_lines(
         [lines.get_line(n) for n in range(start, end + 1)])
     if assignment.levels:

rope/refactor/introduce_parameter.py

         lines = self.pymodule.lines
         start_line = self.pyfunction.get_scope().get_start()
         end_line = self.pymodule.logical_lines.\
-                   get_logical_line_in(start_line)[1]
+                   logical_line_in(start_line)[1]
         start = lines.get_line_start(start_line)
         end = lines.get_line_end(end_line)
         start = self.pymodule.source_code.find('def', start) + 4

rope/refactor/sourceutils.py

     elif len(node.body) > 1:
         start_line = node.body[1].lineno
 
-    end_line = pymodule.logical_lines.get_logical_line_in(scope.get_end())[1]
+    end_line = pymodule.logical_lines.logical_line_in(scope.get_end())[1]
     start = lines.get_line_start(start_line)
     end = min(lines.get_line_end(end_line) + 1, len(pymodule.source_code))
     return start, end

ropetest/codeanalyzetest.py

     def test_normal_lines(self):
         code = 'a_var = 10'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((1, 1), line_finder.get_logical_line_in(1))
+        self.assertEquals((1, 1), line_finder.logical_line_in(1))
 
     def test_normal_lines2(self):
         code = 'another = 10\na_var = 20\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((1, 1), line_finder.get_logical_line_in(1))
-        self.assertEquals((2, 2), line_finder.get_logical_line_in(2))
+        self.assertEquals((1, 1), line_finder.logical_line_in(1))
+        self.assertEquals((2, 2), line_finder.logical_line_in(2))
 
     def test_implicit_continuation(self):
         code = 'a_var = 3 + \\\n    4 + \\\n    5'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((1, 3), line_finder.get_logical_line_in(2))
+        self.assertEquals((1, 3), line_finder.logical_line_in(2))
 
     def test_explicit_continuation(self):
         code = 'print 2\na_var = (3 + \n    4, \n    5)\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((2, 4), line_finder.get_logical_line_in(2))
+        self.assertEquals((2, 4), line_finder.logical_line_in(2))
 
     def test_explicit_continuation_comments(self):
         code = '#\na_var = 3\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((2, 2), line_finder.get_logical_line_in(2))
+        self.assertEquals((2, 2), line_finder.logical_line_in(2))
 
     def test_multiple_indented_ifs(self):
         code = 'if True:\n    if True:\n        if True:\n            pass\n    a = 10\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((5, 5), line_finder.get_logical_line_in(5))
+        self.assertEquals((5, 5), line_finder.logical_line_in(5))
 
     def test_list_comprehensions_and_fors(self):
         code = 'a_list = [i\n    for i in range(10)]\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((1, 2), line_finder.get_logical_line_in(2))
+        self.assertEquals((1, 2), line_finder.logical_line_in(2))
 
     def test_generator_expressions_and_fors(self):
         code = 'a_list = (i\n    for i in range(10))\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((1, 2), line_finder.get_logical_line_in(2))
+        self.assertEquals((1, 2), line_finder.logical_line_in(2))
 
     def test_fors_and_block_start(self):
         code = 'l = range(10)\nfor i in l:\n    print i\n'
         code = 'if True:\n    if True:\n        if True:\n            pass\n' \
                '    a = \\\n        1\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((5, 6), line_finder.get_logical_line_in(6))
+        self.assertEquals((5, 6), line_finder.logical_line_in(6))
 
     def test_problems_with_inner_indentations2(self):
         code = 'if True:\n    if True:\n        pass\n' \
                'a = 1\n'
         line_finder = LogicalLineFinder(SourceLinesAdapter(code))
-        self.assertEquals((4, 4), line_finder.get_logical_line_in(4))
+        self.assertEquals((4, 4), line_finder.logical_line_in(4))
 
     def test_generating_line_starts(self):
         code = 'a = 1\na = 2\n\na = 3\n'