Commits

Anonymous committed 93625b5

Some random code cleanups

Comments (0)

Files changed (9)

docs/dev/issues.txt

 Other Possible Goals:
 
 * Finding similar pieces to extracted
-* Formatting?
 
 
 Release Issues
 ===========================
 
 Currently python elements overwrite others with the same name.  This
-makes some problems for some refactorings.
+might cause problems for some refactorings.
 
 
 Enhancing Refactorings

docs/dev/workingon.txt

 Small Stories
 =============
 
-- Using file size for detecting changes, too
-- Clearing redo list after each do
-- Renaming `Timekeeper` to `ChangeIndicator`
+* Commenting based on the line of syntax error in codeassist?
 
 * Updating and adding docs on SOI
 * Adding restructuring scope; local scope, module, all files?
 * Better search triggering in find type dialog
 * Some of the things in `codeanalyze.WordFinder` can be achieved using
-  asts; make a clone and do them there
+  asts; make a clone and test them there
+* Refactoring codeanalyze; lots of estimations
 * Assignment to parameters in inline method
 * Assignment to parameter warning
-* Refactoring codeanalyze; lots of estimations
 
 * Extracting subexpressions; look at `extracttest` for more info
 * Remove ``change occurreces`` refactoring?

rope/base/codeanalyze.py

                 self.open_count -= 1
                 if self.open_parens:
                     self.open_parens.pop()
-        if current_line.rstrip().endswith('\\'):
+        if current_line and char != '#' and current_line.endswith('\\'):
             self.explicit_continuation = True
         else:
             self.explicit_continuation = False

rope/base/default_config.py

     #   'shelve' but probably more reliable.  But it is much less CPU
     #   efficient.
     #
-    # The choice of the objectdb might be hard.  I prefer
-    # 'persisted_memory' and think it is the best.  For large
-    # projects I prefer 'shelve'.  If you encounter mysterious
-    # problems when using 'shelve' use the slower 'sqlite'.
+    # 'persisted_memory' is the best most of the time.  If your
+    # project is very large, you might consider 'shelve' or the
+    # slower 'sqlite'.
     prefs['objectdb_type'] = 'persisted_memory'
 
     # Shows whether to save history across sessions.  Defaults to

rope/ide/codeassist.py

     """A completion proposal
 
     The `kind` instance variable shows the kind of the proposal and
-    can be ``global``, ``local``, ``builtin``, ``attribute``,
-    ``keyword``, ``parameter_keyword``, and ``template``.
+    can be 'global', 'local', 'builtin', 'attribute', 'keyword',
+    'parameter_keyword', and 'template'.
 
     The `type` instance variable shows the type of the proposal and
-    can be ``variable``, ``class``, ``function``, ``imported`` ,
-    ``paramter`` and `None`.
+    can be 'variable', 'class', 'function', 'imported' , 'paramter'
+    and `None`.
 
     """
 
 class Template(object):
     """Templates reported by CodeAssist
 
-    Variables in templates are in the format ${variable}. To put
-    a dollar sign in the template put $$. To set the place of the
-    cursor use ${cursor}.
+    Variables in templates are in ``${variable}`` format. To put a
+    dollar sign in the template put $$. To set the place of the cursor
+    use ${cursor}.
     """
 
     def __init__(self, template):
     var_pattern = re.compile(r'((?<=[^\$])|^)\${(?P<variable>[a-zA-Z][\w]*)}')
 
     def variables(self):
-        """Returns the list of variables sorted by their order
-        of occurence in the template
+        """Get template variables
+        
+        Return the list of variables sorted by their order of
+        occurence in the template.
+
         """
         result = []
         for match in self.var_pattern.finditer(self.template):
     """A CodeAssist result.
 
     Attribute:
-    completions -- A list of CompletionProposals
-    templates -- A list of TemplateProposals
+    completions -- A list of `CompletionProposal`\s
+    templates -- A list of `TemplateProposal`\s
     start_offset -- completion start offset
 
     """
                          starting_offset)
 
     def get_definition_location(self, source_code, offset, resource=None):
-        return _GetDefinitionLocation(self.project, source_code,
-                                      offset, resource).get_definition_location()
+        return _GetDefinitionLocation(self.project, source_code, offset,
+                                      resource).get_definition_location()
 
     def get_doc(self, source_code, offset, resource=None):
         pymodule = get_pymodule(self.project.pycore, source_code, resource)
 
     def __init__(self, code_assist_proposals):
         self.proposals = code_assist_proposals
+        self.preference = ['class', 'function', 'variable',
+                           'parameter', 'imported', None]
 
     def get_sorted_proposal_list(self):
         local_proposals = []
         return result
 
     def _pyname_proposal_cmp(self, proposal1, proposal2):
-        preference = ['class', 'function', 'variable',
-                      'parameter', 'imported', None]
         if proposal1.type != proposal2.type:
-            return cmp(preference.index(proposal1.type),
-                       preference.index(proposal2.type))
-        return self._compare_names_with_under_lines(proposal1.name,
-                                                    proposal2.name)
+            return cmp(self.preference.index(proposal1.type),
+                       self.preference.index(proposal2.type))
+        return self._compare_underlined_names(proposal1.name,
+                                              proposal2.name)
 
-    def _compare_names_with_under_lines(self, name1, name2):
+    def _compare_underlined_names(self, name1, name2):
         def underline_count(name):
             result = 0
             while result < len(name) and name[result] == '_':

rope/refactor/localtofield.py

                pyname in holding_scope.get_names().values() and \
                holding_scope.get_kind() == 'Function' and \
                parent is not None and parent.get_kind() == 'Class'
-

rope/ui/indenter.py

         self._set_line_indents(lineno, new_indents)
 
     def indent(self, lineno):
-        """Indents a line"""
+        """Indent a line"""
         current_indents = self._count_line_indents(lineno)
         new_indents = current_indents + self.indents
         self._set_line_indents(lineno, new_indents)
 
     def entering_new_line(self, lineno):
-        """Indents a line using `correct_indentation` and last line indents"""
+        """Indent a line
+
+        Uses `correct_indentation` and last line indents
+        """
         last_line = ""
         if lineno > 1:
             last_line = self.line_editor.get_line(lineno - 1)
     def __init__(self, editor, indents=4):
         super(PythonCodeIndenter, self).__init__(editor, indents)
 
-    def _get_last_non_empty_line(self, lineno):
+    def _last_non_blank(self, lineno):
         current_line = lineno - 1
         while current_line != 1 and \
-                  self.line_editor.get_line(current_line).strip() == '':
+              self.line_editor.get_line(current_line).strip() == '':
             current_line -= 1
         return current_line
 
-    def _get_starting_backslash_line(self, lineno):
-        current = lineno
-        while current != 1:
-            new_line = current - 1
-            if not self.line_editor.get_line(new_line).rstrip().endswith('\\'):
-                return current
-            current = new_line
-        return 1
-
     def _get_correct_indentation(self, lineno):
         if lineno == 1:
             return 0
         new_indent = self._get_base_indentation(lineno)
 
-        prev_lineno = self._get_last_non_empty_line(lineno)
+        prev_lineno = self._last_non_blank(lineno)
         prev_line = self.line_editor.get_line(prev_lineno)
         if prev_lineno == lineno or prev_line.strip() == '':
             new_indent = 0
         current_line = self.line_editor.get_line(lineno)
-        new_indent += self._get_indentation_changes_caused_by_current_stmt(current_line)
+        new_indent += self._indents_caused_by_current_stmt(current_line)
         return new_indent
 
     def _get_base_indentation(self, lineno):
         range_finder = codeanalyze.StatementRangeFinder(
-            self.line_editor, self._get_last_non_empty_line(lineno))
+            self.line_editor, self._last_non_blank(lineno))
         start = range_finder.get_statement_start()
         if not range_finder.is_line_continued():
-            changes = self._get_indentation_changes_caused_by_prev_stmt(
-                (start, self._get_last_non_empty_line(lineno)))
+            changes = self._indents_caused_by_prev_stmt(
+                (start, self._last_non_blank(lineno)))
             return self._count_line_indents(start) + changes
         if range_finder.last_open_parens():
             open_parens = range_finder.last_open_parens()
-            if self.line_editor.get_line(open_parens[0])[open_parens[1] + 1:].strip() == '':
+            parens_line = self.line_editor.get_line(open_parens[0])
+            if parens_line[open_parens[1] + 1:].strip() == '':
                 if len(range_finder.open_parens) > 1:
                     return range_finder.open_parens[-2][1] + 1
                 else:
                 else:
                     return len(start_line) + 1
         else:
-            return self._count_line_indents(self._get_last_non_empty_line(lineno))
+            return self._count_line_indents(self._last_non_blank(lineno))
 
-
-    def _get_indentation_changes_caused_by_prev_stmt(self, stmt_range):
+    def _indents_caused_by_prev_stmt(self, stmt_range):
         first_line = self.line_editor.get_line(stmt_range[0])
         last_line = self.line_editor.get_line(stmt_range[1])
         new_indent = 0
             new_indent -= self.indents
         return new_indent
 
-    def _get_indentation_changes_caused_by_current_stmt(self, current_line):
+    def _indents_caused_by_current_stmt(self, current_line):
         new_indent = 0
         if current_line.strip() == 'else:':
             new_indent -= self.indents
     def correct_indentation(self, lineno):
         """Correct the indentation of the line containing the given index"""
         self._set_line_indents(lineno, self._get_correct_indentation(lineno))
-

ropetest/ide/codeassisttest.py

         doc = self.assist.get_doc(src, src.rindex('replace') + 1)
         self.assertTrue(doc is not None)
 
-    # TODO: should comment till the end of scope and not block
-    def xxx_test_not_proposing_variables_defined_till_the_end_of_scope(self):
+    def test_proposing_variables_defined_till_the_end_of_scope(self):
         code = 'if True:\n    a_v\na_var = 10\n'
         result = self.assist.assist(code, code.index('a_v') + 3)
-        self.assert_completion_not_in_result('a_var', 'global', result)
+        self.assert_completion_in_result('a_var', 'global', result)
 
     def test_completing_in_uncomplete_try_blocks(self):
         code = 'try:\n    a_var = 10\n    a_'

ropetest/ui/indentertest.py

         self.assertEquals('def f():\n    return (2,\n            3)\na = 10',
                           self.editor.get_text())
 
-    # TODO: handle this case
-    def xxx_test_ignoring_back_slash_in_comments(self):
+    def test_ignoring_back_slash_in_comments(self):
         self.editor.set_text('# hello \\\na = 10')
         self.indenter.correct_indentation(2)
         self.assertEquals('# hello \\\na = 10', self.editor.get_text())
 
-
     def test_entering_a_new_line(self):
         self.editor.set_text('\n')
         self.indenter.entering_new_line(0)