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

name conflict with builtin modules #2019

Open
sohaiberrabii opened this issue Jul 19, 2024 · 2 comments
Open

name conflict with builtin modules #2019

sohaiberrabii opened this issue Jul 19, 2024 · 2 comments
Labels

Comments

@sohaiberrabii
Copy link

When a library uses module names that conflicts with builtins, such as _ast.py, the import logic in https://github.com/davidhalter/jedi/blob/master/jedi/inference/compiled/subprocess/functions.py#L139 ends up using importlib.machinery.BuiltinImporter as it appears before importlib.machinery.PathFinder in sys.meta_path.

@davidhalter
Copy link
Owner

What's your directory structure? I would guess that this is a won't fix from our side, because the import logic probably checks sys.modules first, which loads some modules first.

IMO it's a very very bad idea anyway to overwrite top level builtins. It should be fine to use something like from jedi import _ast though.

@sohaiberrabii
Copy link
Author

This came up when I tried using jedi-vim's goto on a symbol defined in the module. The module itself is from an editable installed package.

It doesn't overwrite the builtin, only shares the name. It's not a top-level module and internally the package is using relative import from ._ast import *. In the following code, the goto-command of jedi-vim will fail for both even though Foo is not defined in a builtin.

from localpackage._ast import Foo
from _ast import AST # builtin 

Its a pretty rare use case, I only opened the issue in case someone else encounters it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants