Visual Studio Code is not suggesting relative imports

Viewed 56

For some reason, if I have a variable inside my project, Vscode stopped suggesting imports when i press Ctrl + Space.

For example, I have a class in types.py:

class StepStatus(ExtendedEnum):
    RUNNING = "RUNNING"
    ERROR = "ERROR"
    OK = "OK"

At the same level, another file called runner.py, but if try to auto import this variable it raises no suggestions: enter image description here

But if I manually import the StepStatus variable it exists:

enter image description here

There is my vscode settings.json content:

{
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        },
    },
    "isort.args": [
        "--profile",
        "black"
    ],
    "python.analysis.extraPaths": [
        "${workspaceFolder}"
    ],
    "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "Material Theme High Contrast",
    "window.zoomLevel": 1,
    "terminal.integrated.inheritEnv": false
}

I already tried to reinstall Vscode, reinstall Pylance extension, delete cache but nothing works. The auto import suggestions only works for the default libraries such as json, typing, datetime...

1 Answers

If there is no StepStatus class in your script, how does IntelliSense prompt?

So I guess you have the following code under your types.py script


class StepStatus(ExtendedEnum):
    RUNNING = "RUNNING"
    ERROR = "ERROR"
    OK = "OK"


Then intellisense will be provided when you type StepStatus in the runner.py script in the same directory:

enter image description here

Enter or select, it will be imported automatically

enter image description here

Type . and smart suggestions also work

enter image description here

Related