Source

rope_py3k / rope / contrib / codeassist.py

Diff from to

File rope/contrib/codeassist.py

             try:
                 function_pyname = rope.base.evaluate.\
                     eval_str(scope, primary)
-            except exceptions.BadIdentifierError, e:
+            except exceptions.BadIdentifierError as e:
                 return {}
             if function_pyname is not None:
                 pyobject = function_pyname.get_object()
             scope_proposals = proposals.get(scope, [])
             scope_proposals = [proposal for proposal in scope_proposals
                               if proposal.type in self.typerank]
-            scope_proposals.sort(self._proposal_cmp)
+            scope_proposals.sort(key = self._proposal_cmp)
             result.extend(scope_proposals)
         return result
 
-    def _proposal_cmp(self, proposal1, proposal2):
-        if proposal1.type != proposal2.type:
-            return cmp(self.typerank.get(proposal1.type, 100),
-                       self.typerank.get(proposal2.type, 100))
-        return self._compare_underlined_names(proposal1.name,
-                                              proposal2.name)
+    def _proposal_cmp(self, proposal):
+        def underline_count(name):
+            result = 0
+            while result < len(name) and name[result] == '_':
+                result += 1
+            return result
+        return (self.typerank.get(proposal.type, 100), underline_count(proposal.name), proposal.name)
 
     def _compare_underlined_names(self, name1, name2):
         def underline_count(name):
         # and split into a list of lines:
         lines = docstring.expandtabs().splitlines()
         # Determine minimum indentation (first line doesn't count):
-        indent = sys.maxint
+        indent = sys.maxsize
         for line in lines[1:]:
             stripped = line.lstrip()
             if stripped:
                 indent = min(indent, len(line) - len(stripped))
         # Remove indentation (first line is special):
         trimmed = [lines[0].strip()]
-        if indent < sys.maxint:
+        if indent < sys.maxsize:
             for line in lines[1:]:
                 trimmed.append(line[indent:].rstrip())
         # Strip off trailing and leading blank lines: