davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.28k stars 370 forks source link

Wrong relative imports in unit tests with parallel hierarchy #702

Closed memeplex closed 3 years ago

memeplex commented 7 years ago

I'm having a problem similar to https://github.com/davidhalter/jedi-vim/issues/195, here is a step by step procedure to reproduce the issue:

mkdir /tmp/proj
cd /tmp/proj
mkdir pkg
touch pkg/__init__.py
touch pkg/mod.py
mkdir tests
touch tests/__init__.py
mkdir tests/pkg
touch tests/pkg/__init__.py
touch tests/pkg/test_mod.py
export PYTHONPATH=/tmp/proj:$PYTHONPATH
vim tests/pkg/test_mod.py

Now try to autocomplete import pkg., jedi will suggest only test_mod, which is wrong given the PYTHONPATH, and won't suggest mod, which is also wrong.

Now, if you edit pkg/mod.py instead, import pkg. will correctly suggest mod. It is as if the file being edited is influencing jedi's notion of the python path.

davidhalter commented 7 years ago

Setting PYTHONPATH is not respected in VIMs Python. We could potentially do that in jedi-vim. What do you think @blueyed ?

blueyed commented 7 years ago

Do you mean to massage sys.path for Jedi, or some other way?

davidhalter commented 7 years ago

Yeah, exactly. Not saying that it's a good idea at the moment, but somewhere in the future if virtualenvs are supported?!

uvesten commented 7 years ago

I'm having the exact same problem, is there any workaround at the moment?

davidhalter commented 3 years ago

Latest Jedi is way way smarter about this stuff and thanks to your reproduction case I was able to see that this has been solved.