`source.organizeImports` doesn't remove unused imports
See original GitHub issuesource.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]
- import some unused things (in non-alphabetical order so you know it’s running
source.organizeImports
)
from typing import List, Dict
- save the file
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
XXX
Issue Analytics
- State:
- Created 2 years ago
- Reactions:24
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 viasource.fixAll.unusedImports
though not sure how many sub-configs there are.Thanks for the reference!