mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 20:42:10 +00:00
Handle keyword comments between = and value (#6883)
## Summary This PR adds comment handling for comments between the `=` and the `value` for keywords, as in the following cases: ```python func( x # dangling = # dangling # dangling 1, ** # dangling y ) ``` (Comments after the `**` were already handled in some cases, but I've unified the handling with the `=` handling.) Note that, previously, comments between the `**` and its value were rendered as trailing comments on the value (so they'd appear after `y`). This struck me as odd since it effectively re-ordered the comment with respect to its closest AST node (the value). I've made them leading comments, though I don't know that that's a significant improvement. I could also imagine us leaving them where they are.
This commit is contained in:
parent
a3f4d7745a
commit
e2b2b1759f
7 changed files with 211 additions and 17 deletions
|
@ -40,6 +40,8 @@ impl Format<PyFormatContext<'_>> for KeyValuePair<'_> {
|
|||
])]
|
||||
)
|
||||
} else {
|
||||
// TODO(charlie): Make these dangling comments on the `ExprDict`, and identify them
|
||||
// dynamically, so as to avoid the parent rendering its child's comments.
|
||||
let comments = f.context().comments().clone();
|
||||
let leading_value_comments = comments.leading(self.value);
|
||||
write!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue