Friday, October 7, 2022

[SOLVED] VSCode unable to autoimport python functions

Issue

I am currently able to use quick fix to auto import python functions from external typings such as from typing import List.

rel="nofollow noreferrer">Python module quick fix import

However, I am unable to detect local functions/classes for import. For example: If I have the data class SampleDataClass in dataclasses.py, and I reference it in a function in test_file.py, VSCode is unable to detect it and I have to manually type out the import path for the dataclass.

Definition of dataclass

Reference to dataclass

I have the following extensions enabled:

  • Python
  • Pylance
  • Intellicode

My settings.json includes:

{
  "python.envFile": "${workspaceFolder}/.env",
  "python.languageServer": "Pylance",
  "python.analysis.indexing": true,
  "python.formatting.provider": "black",
  "python.analysis.autoImportCompletions": true,
  "python.analysis.autoSearchPaths": true,
  "python.autoComplete.extraPaths": ["~/Development/<django repo name>/server"],
  "python.analysis.extraPaths": ["~/Development/<django repo name>/server"],
  "vsintellicode.features.python.deepLearning": "enabled",
}

I am using poetry for my virtual environment which is located at ~/Development/<django repo name>/.venv

Is there something that I'm missing?


Solution

Turns out the latest versions for Pylance broke quick-fix imports and any extra path settings for VSCode. When I rolled back the version to v2022.8.50 it now works again.

I filed an issue here: https://github.com/microsoft/pylance-release/issues/3353.



Answered By - Erik
Answer Checked By - Willingham (WPSolving Volunteer)