-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort imports on save is very buggy #4831
Comments
I'm unable to reproduce any of these behaviors. However I do sometimes find that import will be seemingly repeated for a second and then fixed, but even that is pretty rare. I use these settings:
I've been using them for some time without much issue, but I only used a clean environment with those exact settings for a bit so I could've missed those glitches. In case it's specific to your settings, could you verify if they are the same or different? |
Encountered same issue. Every time pressed Ctrl-S, imports get formatted differently. Quickly pressing multiple Ctrl-S even causes the file to be seemingly modified concurrently by two sorting processes, and in turn causes import statements to be messy or deleted. I think the behaviour I saw is similar to the one presented in #8245 . |
This issue is still there for VSCode v1.41.1. Right click + Sort imports works fine but subsequent sorting on save keeps reformatting the imports or even arbitrarily deleting some (!) |
Hello, I was looking at the linked issues, and it looks like the main isort inconsistency / data loss issues reported are:
I was wondering if the current issue is a separate issue from the above three and if so whether it's still ongoing. Thanks! |
Was trying to get As of now this "python.formatting.provider": "black",
"python.languageServer": "Pylance",
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.python",
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
Would be ideal to pipe each stage into the next for a clean single UI update/file save. It is most noticeable when there's a tuple of imports.... like: from .models import (
Model1,
Model2
Model3,
Model4,
Model5,
Model6,
Model7,
Model8,
Model9,
Model10,
) You see the sorting happen and the imports get compressed to a line or two, and then black will format the newly sorted imports. |
Related: #5748 |
The sorting imports functionality is a mess :| |
Some issues mentioned here are fixed now. I recommend everyone to open up new issues if they encounter it. @Zacharias030 |
Will do! Unfortunately I still have problems, will open a new issue with specifics.
Am 12. Aug. 2020, 15:21 +0200 schrieb Kartik Raj <notifications@github.com>:
… Some issues mentioned here are fixed now. I can recommend everyone to open up new issues if they encounter it. @Zacharias030
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I still get imports deleted automagically when I apply:
My setup description is VSCode 1.45.1 on Windows10. It's been a year and this simple issue remains unresolved somehow... |
microsoft/vscode-python#4831 There are still several related open issues in microsoft/vscode-python, but this seems to be working as of ms-python.python@2020.10.332292344.
Ridiculously slow to sort imports. Buggy, slow, magical deletions.
|
Can people please try https://marketplace.visualstudio.com/items?itemName=ms-python.isort and let us know if it solves their issues? |
Just ran into the same problem where VSCode with isort would delete unused import statements even in a try/except block such as: def ready(self):
try:
import pdj.users.signals
except ImportError:
pass Extension as suggested by @brettcannon fixed the issue. Thank you |
Actually my bad, I think I spoke to soon, still have the same issue even after installing the extension! There is a definitely a conflict somewhere with isort/black and formatting on save. Upon further checking, I noticed that I had |
@oizik The
Closing this, since this is by design. You could file a bug on |
@karthiknadig The issue raised by @oizik is independent of this issue and has nothing to do with it. Citing it as closing reason does not make sense. Please reopen this issue since it is not addressed yet. |
@Spenhouet the resolution is to use https://marketplace.visualstudio.com/items?itemName=ms-python.isort . That will be the future home to import sorting support. That extension runs |
@Spenhouet Looks like the name that |
Problems:
(add 4-5 imports with relative imports, every time you save, the imports get formatted differently)
The text was updated successfully, but these errors were encountered: