Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportedModule always assumes paths to be relative to current resource #3

Open
mcepl opened this issue Nov 30, 2013 · 2 comments
Open

Comments

@mcepl
Copy link
Contributor

mcepl commented Nov 30, 2013

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
Copy link
Contributor Author

mcepl commented Nov 30, 2013

Probably, but I have long since switched to Jedi.

@mcepl
Copy link
Contributor Author

mcepl commented Nov 30, 2013

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

@ghost ghost assigned mcepl Dec 2, 2013
@mcepl mcepl removed their assignment Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant