-
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
Preserve end-of-line comments on import-from statements #6216
Conversation
3b16233
to
af04b20
Compare
We can probably generalize some of this for other container types (lists, sets, etc). |
(I'm looking into it.) |
PR Check ResultsBenchmarkLinux
Windows
|
crates/ruff_python_formatter/tests/snapshots/format@statement__import_from.py.snap
Outdated
Show resolved
Hide resolved
bd8f7dd
to
c5732e8
Compare
Okay, hopefully good to go. |
let mut tokens = | ||
SimpleTokenizer::up_to_without_back_comment(comment.start(), locator.contents()) | ||
.skip_trivia(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would love to remove the backward lexing if possible in the future. It kind of works, but I'm worried that we'll run into issues sooner or later (e.g. magic commands are interesting...) . Could we instead search forward from the end of the identifier (or the start of the statement if absent)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I figured out a solution that doesn't require lexing. If the comment is end-of-line, and between the start of the statement and the first member, it has to be immediately following the parenthesis.
c5732e8
to
2ebf7b2
Compare
Summary
Ensures that we keep comments at the end-of-line in cases like:
Closes #6067.