-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve trailing inline comments on import-from statements (#12498)
## Summary Right now, in the isort comment model, there's nowhere for trailing comments on the _statement_ to go, as in: ```python from mylib import ( MyClient, MyMgmtClient, ) # some comment ``` If the comment is on the _alias_, we do preserve it, because we attach it to the alias, as in: ```python from mylib import ( MyClient, MyMgmtClient, # some comment ) ``` Similarly, if the comment is trailing on an import statement (non-`from`), we again attach it to the alias, because it can't be parenthesized, as in: ```python import foo # some comment ``` This PR adds logic to track and preserve those trailing comments. We also no longer drop several other comments, like: ```python from mylib import ( # some comment MyClient ) ``` Closes #12487.
- Loading branch information
1 parent
2ceac5f
commit 7571da8
Showing
9 changed files
with
321 additions
and
32 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
crates/ruff_linter/resources/test/fixtures/isort/trailing_comment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from mylib import ( | ||
MyClient, | ||
MyMgmtClient, | ||
) # some comment | ||
|
||
pass | ||
|
||
from mylib import ( | ||
MyClient, | ||
MyMgmtClient, | ||
); from foo import ( | ||
bar | ||
)# some comment | ||
|
||
pass | ||
|
||
from foo import ( | ||
bar | ||
) | ||
from mylib import ( | ||
MyClient, | ||
MyMgmtClient, | ||
# some comment | ||
) | ||
|
||
pass | ||
|
||
from mylib import ( | ||
MyClient, | ||
# some comment | ||
) | ||
|
||
pass | ||
|
||
from mylib import ( | ||
MyClient | ||
# some comment | ||
) | ||
|
||
pass | ||
|
||
from mylib import ( | ||
# some comment | ||
MyClient | ||
) | ||
|
||
pass | ||
|
||
# a | ||
from mylib import ( # b | ||
# c | ||
MyClient # d | ||
# e | ||
) # f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.