question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`source.organizeImports` doesn't remove unused imports

See original GitHub issue

source.organizeImports does not remove unused imports

Environment data

  • VS Code version: 1.60
  • Extension version (available under the Extensions sidebar): v2021.9.1230869389
  • OS and version: windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: XXX
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Value of the python.languageServer setting: default

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

unused imports are removed, according to https://github.com/microsoft/vscode/issues/107535 it’s supposed to

Actual behaviour

unused imports are not removed

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. import some unused things (in non-alphabetical order so you know it’s running source.organizeImports)
from typing import List, Dict
  1. save the file

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:24
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
micimizecommented, Dec 22, 2022

Automatic unused import removal can be configured in pylance as of august: https://devblogs.microsoft.com/python/python-in-visual-studio-code-august-2022-release/#remove-all-unused-imports

Granular source.fixAll configuration can be done via source.fixAll.unusedImports though not sure how many sub-configs there are.

0reactions
karrtikrcommented, Dec 22, 2022

Thanks for the reference!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to enable source.organizeImports without ...
organizeImports ": true },. Love the sorting, but don't like that Visual Studio Code is removing unused imports vs greying them out.
Read more >
Remove Unused Imports - Visual Studio Marketplace
Extension for Visual Studio Code - Removes unused ES6 imports in JavaScript and TypeScript files without changing the order.
Read more >
How to remove unused imports in VSCode. - LinkedIn
Here's a shortcut 😉 to fix these issues. In MAC, It is [Ctrl + Option + O], also for some it is [Option...
Read more >
560631 – "Remove unused imports" does not work (anymore)
In brief: Clean Up > Eclipse [built in] does NOT "Remove unused imports" is Save Actiopns > Organize imports is NOT checked! This...
Read more >
How to Remove all Unused imports in a Java file - Javarevisited
Though unused import in Java file does not create any harm, it's unnecessary to increase the length and size of Java source file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found