pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

"Add import" code action can add import after imported symbol usage

Open debonte opened this issue 1 year ago • 2 comments

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

  1. Put cursor on environ
  2. 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

debonte avatar Jan 31 '24 00:01 debonte

I can also repro when there's no existing imports for the same module.

Repro steps:

  1. Open https://github.com/microsoft/pylance-release/blob/247c5fcd1f18670ea101481474f19b4606dbd20c/testing/single/src/codeaction in vscode
  2. Run Add 'import os' on line 7
  3. Run Add 'from pathlib import Path' on line 11
  4. Observe Add 'from pathlib import Path' is added on line 28

StellaHuang95 avatar Apr 11 '24 01:04 StellaHuang95

@StellaHuang95, looks like these are different bugs. Your issue is a recent regression (2024.2.100).

debonte avatar Apr 11 '24 01:04 debonte