-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
isort removes newlines before standalone comments if the following line is an import of the same group #251
Comments
Black puts an empty line after every group of imports. A standalone comment signifies an end of a group of imports before it. So, your example is wrong, Black will do this instead with the original file: --- /tmp/asd.py (original)
+++ /tmp/asd.py (formatted)
@@ -1,4 +1,5 @@
import a
+
# noinspection PyProtectedMember
import _a The behavior between isort and Black is indeed different here. I haven't decided yet how to resolve this. |
Thanks for the explanation, would be nice to somehow support this use case though. |
I am affected by this as well :/ Just to clarify, what is the problem here? Is Black wrong, or is isort? Is the newline supposed to be there? |
@ambv any plans to address this? This makes the line of |
I'm also affected. what is the current status about this bug? |
I think black is being too prescriptive here: yes comments between imports can be used as headers, but they can also be things like: import a
# XXX: unused import, that however shouldn't be removed
# because our framework depends on it being present
import b |
Apparently black and isort do not behave the same. See : psf/black#251
Apparently black and isort do not behave the same. See : psf/black#251
Apparently black and isort do not behave the same. See : psf/black#251
Hello @ambv ! Do you have an update on this?
Perhaps you can talk through your thoughts so we understand if a fix is likely? Also, re:
Is there some documentation that describes this behavior? I couldn't find it in the code style - I ask because without knowing the reasoning behind this behavior, I find it hard to suggest a way forward. I do find the rest of the decisions well documented, and do a great job of answering my questions and feature requests before I make them ;) |
…if the following line is an import of the same group
Does anyone know what the best way to get a contributor's attention here is? I'm happy to submit a proposal + fix, it's just that the radio silence makes me nervous about investing time :) |
Any update on this ? What is the current status of this issue ? Not sure which way to proceed here .... Black or isort ? |
This adds a `ensure_newline_before_comments` configuration that matches the format that `black` imposes (for better or worse) and allows `isort` to be used with `black` without any thrashing/conflicts with regards to blank lines before comments. Should help address psf/black#251
This is now fixed in isort by adding a new If you use pre-commit, you can pin to the latest isort commit, like this: |
Nearly perfect match config to black formatting with one exception: psf/black#251 Signed-off-by: Chris Patterson <[email protected]>
Nearly perfect match config to black formatting with one exception: psf/black#251 That gap should be filled with the 'ensure_newline_before_comments=True' that won't be honored until the next version of isort. Signed-off-by: Chris Patterson <[email protected]>
A few comments between imports were removed or moved to the top of the import block, due to behavioral differences between black and isort. See psf/black#251 for details. In two instances @Overloads at the top of the file needed to be moved due to psf/black#1490.
A few comments between imports were removed or moved to the top of the import block, due to behavioral differences between black and isort. See psf/black#251 for details. In two instances @Overloads at the top of the file needed to be moved due to psf/black#1490.
A few comments between imports were removed or moved to the top of the import block, due to behavioral differences between black and isort. See psf/black#251 for details. In two instances @Overloads at the top of the file needed to be moved due to psf/black#1490.
Comments in import blocks cause disagreement between Black and isort. This will soon be fixed by specifying 'ensure_newline_before_comments=true' in the isort config, though this won't be honoured until the next isort release. See psf/black#251 and PyCQA/isort#1000
Comments in import blocks cause disagreement between Black and isort. This will soon be fixed by specifying 'ensure_newline_before_comments=true' in the isort config, though this won't be honoured until the next isort release. See psf/black#251 and PyCQA/isort#1000
Comments in import blocks cause disagreement between Black and isort. This will soon be fixed by specifying 'ensure_newline_before_comments=true' in the isort config, though this won't be honoured until the next isort release. See psf/black#251 and PyCQA/isort#1000
Comments in import blocks cause disagreement between Black and isort. This will soon be fixed by specifying 'ensure_newline_before_comments=true' in the isort config, though this won't be honoured until the next isort release. See psf/black#251 and PyCQA/isort#1000
Comments in import blocks cause disagreement between Black and isort. This will soon be fixed by specifying 'ensure_newline_before_comments=true' in the isort config, though this won't be honoured until the next isort release. See psf/black#251 and PyCQA/isort#1000
A few comments between imports were removed or moved to the top of the import block, due to behavioral differences between black and isort. See psf/black#251 for details. In two instances @Overloads at the top of the file needed to be moved due to psf/black#1490.
Looks like isort 5.0.0 is scheduled for tomorrow! |
By the way, I have switched to https://github.com/asottile/reorder_python_imports, which doesn't have this problem and runs statically without isort's troubles when the sorted packages aren't installed. |
Closing as isort 5 has been released. Either use isort 5's profiles of which one is built for Black, or manually configure |
Operating system: Arch Linux
Python version: Python 3.6.6
Black version: 18.5b0
Does also happen on master: yes
Given:
Black formats this to (note the introduced empty line):
However isort correctly (in the recommended mode 3) formats it to:
The text was updated successfully, but these errors were encountered: