-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
Handle inline comments for imports #125
Comments
Agreed, historically isort hasn't done this because it adds a lot more complexity. For instance given:
Considering the imports end up as:
Where should the comments go? And what about dealing with line length limits etc? from a import b, c # comment 1, comment 2 is after all, much better then stripping potentially useful comments. Thank you for bringing this up, will fix and then deploy a new release. ~Tim |
Glad you see it that way. I see the complexity of this, which gets worse with the various multi-line modes. I think though, comments in imports are fairly common, so handling them seems worth an effort. Yes, concatenating comments seems to be the best possible solution. That way no comments get lost and the user can edit them manually, if necessary. Concatenating with a comma might lead to ambiguity when the comments already contain commas: from a import b # bar, foos a foobar
from a import f # foo, bars a foobar That would become: from a import b, f # bar, foos a foobar, foo, bars a foobar Maybe better use a semicolon, as it is far less commonly used: from a import b, f # bar, foos a foobar; foo, bars a foobar |
@Bengt, you're right a comma is too overused in comments to use as a separator here. I'll switch to a semicolon as suggested, thanks for pointing this out! ~Tim |
Fixed in version 3.6.0 :) |
Thanks for implementing this. It works almost as expected. I opened an issue for the remaining detail. See #129. |
Going back to the original example,
|
Sorry, the above comment was slightly inaccurate. In fact, this is not an issue with
is left unchanged, whereas
has its comments stripped. |
I've proposed a fix for the above issue in PR #179. |
Sometimes it is useful to comment imports, e.g. to clarify renames:
Currently isort removes such inline comments:
isort should reorder and reformat inline comments properly.
The text was updated successfully, but these errors were encountered: