zjes avatar zjes committed 568092f

Merge to version 0.94 of rope

Comments (0)

Files changed (13)

rope/base/builtins.py

     for name in dir(obj):
         if name == 'None':
             continue
-        child = getattr(obj, name)
+        try:
+            child = getattr(obj, name)
+        except AttributeError:
+            # descriptors are allowed to raise AttributeError
+            # even if they are in dir()
+            continue
         pyobject = None
         if inspect.isclass(child):
             pyobject = BuiltinClass(child, {}, parent=parent)
         elif inspect.isroutine(child):
             if inspect.ismethoddescriptor(child) and "__weakref__" in dir(obj):
                 try:
-                    bobj = child.__get__(obj.__weakref__.__objclass__())
+                    weak = child.__get__(obj.__weakref__.__objclass__())
                 except:
-                    bobj = child
-                pyobject = BuiltinFunction(builtin=bobj, parent=parent)
+                    weak = child
+                pyobject = BuiltinFunction(builtin=weak, parent=parent)
             else:
                 pyobject = BuiltinFunction(builtin=child, parent=parent)
         else:

rope/base/fscommands.py

     try:
         return data.decode(encoding)
     except (UnicodeError, LookupError):
-        # fallback to latin1: it should never fail
+        # fallback to utf-8: it should never fail
         return data.decode('utf-8')
 
 

rope/base/oi/runmod.py

 
         def close(self):
             self.sender.close()
+            sys.settrace(None)
 
     def _realpath(path):
         return os.path.realpath(os.path.abspath(os.path.expanduser(path)))

rope/base/pycore.py

 
     def get_module(self, name, folder=None):
         """Returns a `PyObject` if the module was found."""
+        # check if this is a builtin module
+        pymod = self._builtin_module(name)
+        if pymod is not None:
+            return pymod
         module = self.find_module(name, folder)
         if module is None:
-            module = self._builtin_module(name)
-            if module is None:
-                raise ModuleNotFoundError('Module %s not found' % name)
-            return module
+            raise ModuleNotFoundError('Module %s not found' % name)
         return self.resource_to_pyobject(module)
 
     def _builtin_submodules(self, modname):

rope/base/pyobjectsdef.py

         level = 0
         if node.level:
             level = node.level
+        if node.module is None and len(node.names) > 0: #Relative import "."
+            self._Import(node)
+            return
         imported_module = pynames.ImportedModule(self.get_module(),
                                                  node.module, level)
         if self._is_ignored_import(imported_module):

rope/base/stdmods.py

             path = os.path.join(dynload_path, name)
             if os.path.isfile(path):
                 if name.endswith('.so') or name.endswith('.dll'):
-                    result.add(os.path.splitext(name)[0])
+                    if "cpython" in name:
+                        result.add(os.path.splitext(os.path.splitext(name)[0])[0])
+                    else:
+                        result.add(os.path.splitext(name)[0])
     return result

rope/base/worder.py

 
     def is_a_name_after_from_import(self, offset):
         try:
-            line_start = self._get_line_start(offset)
+            if len(self.code) > offset and  self.code[offset] == '\n':
+                line_start = self._get_line_start(offset - 1)
+            else:
+                line_start = self._get_line_start(offset)
             last_from = self.code.rindex('from ', line_start, offset)
             from_import = self.code.index(' import ', last_from)
             from_names = from_import + 8

rope/refactor/importutils/module_imports.py

+import functools
 import rope.base.pynames
 from rope.base import ast, utils
 from rope.refactor.importutils import importinfo
         # Writing module docs
         result.extend(after_removing[first_non_blank:first_import])
         # Writing imports
-        sorted_imports = sorted(imports, key = self._compare_import_locations)
+        sorted_imports = sorted(imports, key = functools.cmp_to_key(self._compare_import_locations))
         for stmt in sorted_imports:
             start = self._get_import_location(stmt)
             if stmt != sorted_imports[0]:
             start = stmt.get_old_location()[0]
         return start
 
-    def _compare_import_locations(self, stmt):
-        if stmt.get_new_start() is not None:
-            return stmt.get_new_start()
-        else:
-            return stmt.get_old_location()[0]
+    def _compare_import_locations(self, stmt1, stmt2):
+        def get_location(stmt):
+            if stmt.get_new_start() is not None:
+                return stmt.get_new_start()
+            else:
+                return stmt.get_old_location()[0]
+        return get_location(stmt1) - get_location(stmt2)
 
     def _remove_imports(self, imports):
         lines = self.pymodule.source_code.splitlines(True)
         if node.level:
             level = node.level
         import_info = importinfo.FromImport(
-            node.module, level, self._get_names(node.names))
+            node.module or '', # see comment at rope.base.ast.walk
+            level, self._get_names(node.names))
         start_line = node.lineno
         self.imports.append(importinfo.ImportStatement(
                             import_info, node.lineno, end_line,

rope/refactor/patchedast.py

         for children in reversed(self.children_stack):
             for child in children:
                 if isinstance(child, ast.stmt):
-                    return self.lines.get_line_start(child.lineno)
+                    return child.col_offset \
+                           + self.lines.get_line_start(child.lineno)
         return len(self.source.source)
 
     _operators = {'And': 'and', 'Or': 'or', 'Add': '+', 'Sub': '-', 'Mult': '*',
         children = ['from']
         if node.level:
             children.append('.' * node.level)
-        children.extend([node.module, 'import'])
+        children.extend([node.module or '', # see comment at rope.base.ast.walk
+                         'import'])
         children.extend(self._child_nodes(node.names, ','))
         self._handle(node, children)
 
 
     def _Raise(self, node):
         children = ['raise']
-        if node.type:
-            children.append(node.type)
-        if node.inst:
-            children.append(',')
-            children.append(node.inst)
-        if node.tback:
-            children.append(',')
-            children.append(node.tback)
+        if node.cause:
+            children.append(node.cause)
+        if node.exc:
+            children.append(node.exc)
         self._handle(node, children)
 
     def _Return(self, node):

ropetest/advanced_oi_test.py

         pymod = self.pycore.resource_to_pyobject(mod)
         self.assertEquals(pymod['AClass'].get_object(),
                           pymod['a_var'].get_object())
-    
+
     def test_nested_classes(self):
         mod = testutils.create_module(self.project, 'mod')
         code = 'def a_func():\n    class AClass(object):\n' \
         self.assertEquals(pyscope.get_scopes()[0]['AClass'].get_object(),
                           pyscope['a_var'].get_object())
 
-    
     def test_function_argument_dti2(self):
         mod = testutils.create_module(self.project, 'mod')
         code = 'def a_func(arg, a_builtin_type):\n    pass\n' \
         pymod2 = self.pycore.resource_to_pyobject(mod2)
         self.assertEquals(pymod2['C'].get_object(),
                           pymod['a_var'].get_object())
-    
+
 
 class NewStaticOITest(unittest.TestCase):
 

ropetest/builtinstest.py

     def tearDown(self):
         testutils.remove_project(self.project)
         super(BuiltinTypesTest, self).tearDown()
-    
+
     def test_simple_case(self):
         self.mod.write('l = []\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         c_class = pymod['C'].get_object()
         a_var = pymod['a_var'].get_object()
         self.assertEquals(c_class, a_var.get_type())
-    
+
     def test_get_items_from_slices(self):
         self.mod.write('class C(object):\n    pass\nl = [C()]\na_var = l[:].pop()\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         c_class = pymod['C'].get_object()
         a_var = pymod['a_var'].get_object()
         self.assertEquals(c_class, a_var.get_type())
+
     def test_simple_for_loops(self):
         self.mod.write('class C(object):\n    pass\nl = [C()]\n'
                        'for c in l:\n    a_var = c\n')
         self.mod.write(src)
         self.project.pycore.analyze_module(self.mod)
 
+    def test_abstractmethods_attribute(self):
+        # see http://bugs.python.org/issue10006 for details
+        src = 'class SubType(type): pass\nsubtype = SubType()\n'
+        self.mod.write(src)
+        self.project.pycore.analyze_module(self.mod)
+
+
 class BuiltinModulesTest(unittest.TestCase):
 
     def setUp(self):

ropetest/refactor/movetest.py

         self.project.do(mover.get_changes(self.mod1))
         expected = '%s\n%s' % (code1, code2)
         self.assertEquals(expected, self.mod1.read())
-        
+
+
 if __name__ == '__main__':
     unittest.main()

ropetest/refactor/restructuretest.py

         self.assertEquals('def f(p):\n    return dup(p)\nx = dup("")\n'
                           'i = 1 * 2\n', self.mod.read())
 
+    def test_statement_after_string_and_column(self):
+        mod_text = 'def f(x):\n  if a == "a": raise Exception("test")\n'
+        self.mod.write(mod_text)
+        refactoring = restructure.Restructure(self.project, '${a}', '${a}')
+        self.project.do(refactoring.get_changes())
+        self.assertEquals(mod_text, self.mod.read())
+
 
 if __name__ == '__main__':
     unittest.main()
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.