question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocomplete not working with relative import when using Jedi with Python3.8

See original GitHub issue

Environment 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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

5reactions
erezshcommented, Jan 1, 2020

Verified, works with Python 3.7.6-64 bit. Thanks @karrtikr

I guess Python 3.8 is what breaks it.

0reactions
karrtikrcommented, Sep 21, 2021

This issue seems to be fixed in the latest version of the extension when using Jedi or Pylance, closing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix Python Relative Imports and Auto-completion in VSCode
In this video, you will learn how to properly handle Python relative imports without extending the sys.path. Additionally, you will learn ...
Read more >
Atom IDE autocomplete-python not working - Stack Overflow
If autocomplete-python in Atom not working with Python 3.7 In windows, go to: C:\Users\username\.atom\packages\autocomplete-python\lib\jedi\ ...
Read more >
Jedi Documentation
Github Repository. Jedi is a static analysis tool for Python that is typically used in IDEs/editors plugins.
Read more >
Import could not be resolved - Vesuvio
I'd personally discourage the use of relative imports as they are not as readable ... not be resolved from source Pylance in VS...
Read more >
Absolute and Relative Imports in Python - GeeksforGeeks
Python modules can get access to code from another module by importing the file/function using import. The import statement is the most ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found