pylance-release
pylance-release copied to clipboard
Quick Fix not working for local imports
Environment data
- Language Server version: Python
- OS and version: macOS Monterey
- Python version (& distribution if applicable, e.g. Anaconda): 3.10.4
- Pylance version: v2022.9.20
Comments
I know other people have run into issues with being unable to auto-import locally, which is unavailable (as per this issue). However, to my understanding, you should be able to hover over local imports and quick-fix auto-add the import. I was recently able to do this until I updated my VSCode and extensions recently.
Repro Steps
- Install VSCode with the following extensions:
- Python
- Pylance
- Intellicode
- Create a new python project folder with a venv using poetry.
- Place the following in the settings.json:
{
"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",
}
Expected behavior
Currently, I can quick-fix to auto import python modules that I have defined in my poetry config (and installed in the venv). See the image for an example. I should be able to do the same for functions/classes that I have defined locally (and are in files that are opened in VS Code).

Actual behavior
I am unable to quick-fix import local classes and functions.
Say I define a dataclass of SampleDataClass
in my dataclasses.py
file like so:
Then I attempt to reference that dataclass in a new file called test_file.py
located in the same directory. With both files open I'm still unable to hover over the reference and auto-import the dataclass. See below:
It should work.
Can you provide us some logs as described in the troubleshooting guide?
I would like to see whether we are correctly picking up the file. (do we consider the file as user file?)
Hello @heejaechang,
Same issue here on Pylance v2022.9.10
and v2022.9.20
and most recently v2022.9.30
.
I've tested Pylance v2022.8.50
and for that version the import suggestions do work.
Here are my details, as per the Filing an issue guide:
- Language Server version: Pylance v2022.9.30
- Output:
Pylance language server 2022.9.30 (pyright df789b5e) starting
- Output:
- OS and version: macOS Monterey 12.5.1
- Python version: 3.10.4
Other extensions installed:
- Python
v2022.14.0
- Django
v1.10.0
- IntelliCode
v1.2.27
A code example (or any other additional information) we can use to reproduce the issue.
The example provided by eronning
is perfect.
@heejaechang I've attached some logs for that version. However, it looks like if I either roll back to v2022.8.50
or roll forward to the latest version of v2022.9.40
the issue has been resolved.
Thank you @eronning for letting us know that it works with the latest pylance and providing us the log.
according to your log file
[Info - 10:07:45 AM] (7144) Searching for source files
[Info - 10:07:45 AM] (7144) No source files found.
you seem hitting an old bug that has been fixed in 2022.9.40 (https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2022940-26-september-2022-release)
this issue (Bug Fix: Default includes and excludes weren't being used if a pyproject.toml file was present
(https://github.com/microsoft/pylance-release/issues/3348)) particularly.
since now it is resolved, I will close the issue. thank you.
@heejaechang Hi!
I have a same problem((
I have a class KafkaConsumers but i cannot import it througth quickfix.
What i doing incorrect?
My environment:
Language Server version: Pylance language server 2023.8.20 (pyright fcee52c7) starting OS and version: macOS Monterey 12.6.1 Python version: 3.10.4
I also see log line like
[Error - 17:03:42] (17272) File or directory "/Users/<user>/git/whc-autotests/~/miniconda/envs/whc" does not exist.
But KafkaConsumers its a local code.
And i have the setting like
"python.analysis.include": [
"~/miniconda/envs/whc"
],