Commits

Anonymous committed 54ce709

pycore: simplify _find_module() to return only the resource

Comments (0)

Files changed (1)

rope/base/pycore.py

             observer(resource)
 
     def _find_module_in_folder(self, folder, modname):
-        result = []
         module = folder
         packages = modname.split('.')
         for pkg in packages[:-1]:
             if  module.is_folder() and module.has_child(pkg):
                 module = module.get_child(pkg)
-                result.append(module)
             else:
                 return None
-        if not module.is_folder():
-            return None
-
-        if module.has_child(packages[-1]) and \
-           module.get_child(packages[-1]).is_folder():
-            result.append(module.get_child(packages[-1]))
-            return result
-        elif module.has_child(packages[-1] + '.py') and \
-             not module.get_child(packages[-1] + '.py').is_folder():
-            result.append(module.get_child(packages[-1] + '.py'))
-            return result
-        return None
+        if module.is_folder():
+            if module.has_child(packages[-1]) and \
+               module.get_child(packages[-1]).is_folder():
+                return module.get_child(packages[-1])
+            elif module.has_child(packages[-1] + '.py') and \
+                 not module.get_child(packages[-1] + '.py').is_folder():
+                return module.get_child(packages[-1] + '.py')
 
     def get_python_path_folders(self):
         import rope.base.project
 
         returns None if it can not be found
         """
-        resource_list = self._find_module(modname, folder)
-        if resource_list is not None:
-            return resource_list[-1]
+        return self._find_module(modname, folder)
 
     def find_relative_module(self, modname, folder, level):
         for i in range(level - 1):
         if modname == '':
             return folder
         else:
-            module = self._find_module_in_folder(folder, modname)
-            if module is not None:
-                return module[-1]
+            return self._find_module_in_folder(folder, modname)
 
     def _find_module(self, modname, folder=None):
-        """Returns a list of lists of `Folder`s and `File`s for the given module"""
+        """Return `modname` module resource"""
         for src in self.get_source_folders():
             module = self._find_module_in_folder(src, modname)
             if module is not None: