Autocomplete not working with relative import when using Jedi with Python3.8
See original GitHub issueEnvironment data
- VS Code version: 1.40.2
- Extension version (available under the Extensions sidebar): 2019.11.50794
- OS and version: Windows 10
- Python version (& distribution if applicable, e.g. Anaconda): 3.8
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): None
- Relevant/affected Python packages and their versions: Jedi 0.15.1
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): Jedi
Expected behaviour
autocomplete should work for modules that are imported using from . import ...
Actual behaviour
It doesn’t.
Steps to reproduce:
Put in a directory called bug
two files.
# hello.py
def f1(x: int, b: str):
pass
and
# test.py
from . import hello
print(hello.f1)
and of course an empty __init__.py
file.
I can run test.py
and get the correct result, so I know this is valid python:
$ python -m bug.test
<function f1 at 0x000002907C518B80>
Also, jedi works without an issue:
$ python -c "import jedi; print(jedi.Script(path='test.py', line=2, column=14).completions())"
[<Completion: f1>]
But if I type in test.py
the text hello.
, I will not get autocomplete to suggest f1
. Also, typing hello.f1
doesn’t bring up the autocomplete for f1’s arguments. Also “Go To Definition” doesn’t work on f1.
BUT, if I add import hello
to test.py
, suddenly all three things work.
All these things work with the MS Language Server, but not in Jedi mode.
(I initially opened a bug for Jedi, but it seems like it’s in this extension? https://github.com/davidhalter/jedi/issues/1463)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:10
Verified, works with Python 3.7.6-64 bit. Thanks @karrtikr
I guess Python 3.8 is what breaks it.
This issue seems to be fixed in the latest version of the extension when using Jedi or Pylance, closing this.