pylance-release
pylance-release copied to clipboard
"Add import" code action can add import after imported symbol usage
Environment data
- Language Server version: 2023.12.1
- OS and version: Windows 11
- Python version: 3.12
Code Snippet
environ
from os import path
path
Repro Steps
- Put cursor on
environ
- Execute
Add "from os import environ"
code action
Expected behavior
Import is added above the use of environ
:
from os import environ
environ
from os import path
path
Actual behavior
Import is added after the use of environ
, leaving user with an "environ" is unbound
diagnostic to address.
environ
from os import environ, path
path
I can also repro when there's no existing imports for the same module.
Repro steps:
- Open https://github.com/microsoft/pylance-release/blob/247c5fcd1f18670ea101481474f19b4606dbd20c/testing/single/src/codeaction in vscode
- Run
Add 'import os'
on line 7 - Run
Add 'from pathlib import Path'
on line 11 - Observe
Add 'from pathlib import Path'
is added on line 28
@StellaHuang95, looks like these are different bugs. Your issue is a recent regression (2024.2.100).