-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
Support for magic trailing comma #1683
Comments
I agree, this would be great to add! The only saving grace about the current behavior is that since it forces a trailing comma, it is always black compatible - but it would be nice to be compatible with the spirit of black's formatting approach as well. |
Exactly, it also makes Here's my use case to reproduce the problem:
I have the following file from collections import (defaultdict, namedtuple,) that black turns into multi-line import because of the trailing comma: from collections import (
defaultdict,
namedtuple,
) However, from collections import defaultdict, namedtuple |
Hi, I'm having this problem myself, I would really appreciate support for the magic trailing comma, but I understand it would be another configuration option. If I had some ideas to what to name it, I could try to implement this myself, but I haven't looked at the isort source yet, so that may not be possible for me to do, |
Either way, I think that the name should be the least of your concerns when it comes to implementing it 😄 |
Okay, I'm going to try to work on this :) |
@onerandomusername thanks for taking up this issue! I am assigning this issue to you. |
Black auto-explodes imports, collections, function calls, etc. when they contain a trailing comma:
https://github.com/psf/black/blob/master/docs/the_black_code_style.md#the-magic-trailing-comma
This means that even though this would fit into one line:
Black will NOT convert it into this:
As long as the import list contains a trailing comma.
isort
currently does not have the magic trailing comma handling as far as I can tell and will collapse the import list if it can fit within the line length limit.The text was updated successfully, but these errors were encountered: