rope icon indicating copy to clipboard operation
rope copied to clipboard

ImportedModule always assumes paths to be relative to current resource

Open mcepl opened this issue 10 years ago • 2 comments

I'm using rope inside SublimeRope and have a project that consists of several namespaces, all available on python path. While rope properly indexes those, it cannot resolve ImportedModule nodes pointing from one package to another as with a non-zero level only a relative import will be attempted.

I have changed the local implementation to instead try relative first and fall back to absolute if needed:

class ImportedModule(PyName):

    # ...

    def _get_pymodule(self):
        if self.pymodule.get() is None:
            pycore = self.importing_module.pycore
            if self.resource is not None:
                self.pymodule.set(pycore.resource_to_pyobject(self.resource))
            elif self.module_name is not None:
                try:
                    pymodule = None
                    if self.level > 0:
                        try:
                            pymodule = pycore.get_relative_module(
                                self.module_name, self._current_folder(),
                                self.level)
                        except exceptions.ModuleNotFoundError:
                            pass
                    if pymodule is None:
                        pymodule = pycore.get_module(self.module_name,
                                                     self._current_folder())
                    self.pymodule.set(pymodule)
                except exceptions.ModuleNotFoundError:
                    pass
        return self.pymodule.get()

mcepl avatar Nov 30 '13 23:11 mcepl

Probably, but I have long since switched to Jedi.

mcepl avatar Nov 30 '13 23:11 mcepl

Patch (or pull request) would probably got more attention from the maintainer.

mcepl avatar Nov 30 '13 23:11 mcepl