Closed DetachHead closed 1 year ago
Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 5 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.
i think this is more of a bug than a feature request, because it's not consistent with how the same option works in typescript
Sorting in python is provided by isort
library. This would essentially have to be supported by isort
first, and then we can work with it to provide this. Since there is no implementation of this in the extension, we are treating this as a feature.
Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future.
We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most.
In case others find it useful – until isort support (https://github.com/PyCQA/isort/issues/1105) I'm getting by with an autoflake
as a task which I then trigger on save. It results in some "content of the file is newer" complaints but is mostly fine.
Do note that Pylance provides a code action to remove an unused import:
If you want something that does a larger removal of all unused imports, there's a feature request at https://github.com/microsoft/pylance-release/issues/1722 .
Extension now supports removing unused imports via Pylance. As isort
libary does not provide this feature there's much to be done atm, hence closing this.
Please open a feature request at Pylance if you would to automatically do this on save.
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.
Thanks for the reference!
source.organizeImports
does not remove unused importsEnvironment data
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]
source.organizeImports
)Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)``` XXX ```