You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not a bug per se but something I found rather confusing. The comprehension comment placement associates leading and trailing comments on the ifs as dangling comments of the condition node:
// Handle comments inside comprehensions, e.g.
//
// ```python
// [
// a
// b
// c
// # leading becomes dangling on if
// if # trailing becomes dangling on if
// d
// ]
// ```
This is confusing because nodes that otherwise cannot have dangling comments now suddenly have dangling comments. I ran into this because I added assertions to fmt_dangling_comments in ExprName and ExprCompare to verify that the dangling comments are empty (because that's what the comment says) and got surprised by the assertions failing.
The more common approach is to make the comments dangling comments on the comprehension and then find them again during formatting. This is probably a bit more work. Let's see how it turns out.
The text was updated successfully, but these errors were encountered:
This is not a bug per se but something I found rather confusing. The comprehension comment placement associates leading and trailing comments on the
if
s as dangling comments of the condition node:ruff/crates/ruff_python_formatter/src/comments/placement.rs
Lines 1244 to 1369 in 96d310f
This is confusing because nodes that otherwise cannot have dangling comments now suddenly have dangling comments. I ran into this because I added assertions to
fmt_dangling_comments
inExprName
andExprCompare
to verify that the dangling comments are empty (because that's what the comment says) and got surprised by the assertions failing.The more common approach is to make the comments dangling comments on the comprehension and then find them again during formatting. This is probably a bit more work. Let's see how it turns out.
The text was updated successfully, but these errors were encountered: