mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-21 19:05:09 +00:00
Handle bracketed comments on sequence patterns (#6801)
## Summary This PR ensures that we handle bracketed comments on sequences, like `# comment` here: ```python match x: case [ # comment 1, 2 ]: pass ``` The handling is very similar to other, similar nodes, except that we do need some special logic to determine whether the sequence is parenthesized, similar to our logic for tuples. ## Test Plan `cargo test`
This commit is contained in:
parent
474e8fbcd4
commit
f754ad5898
3 changed files with 93 additions and 32 deletions
|
@ -15,6 +15,7 @@ use crate::expression::expr_tuple::is_tuple_parenthesized;
|
|||
use crate::other::parameters::{
|
||||
assign_argument_separator_comment_placement, find_parameter_separators,
|
||||
};
|
||||
use crate::pattern::pattern_match_sequence::SequenceType;
|
||||
|
||||
/// Manually attach comments to nodes that the default placement gets wrong.
|
||||
pub(super) fn place_comment<'a>(
|
||||
|
@ -179,6 +180,15 @@ fn handle_enclosed_comment<'a>(
|
|||
AnyNodeRef::Comprehension(comprehension) => {
|
||||
handle_comprehension_comment(comment, comprehension, locator)
|
||||
}
|
||||
AnyNodeRef::PatternMatchSequence(pattern_match_sequence) => {
|
||||
if SequenceType::from_pattern(pattern_match_sequence, locator.contents())
|
||||
.is_parenthesized()
|
||||
{
|
||||
handle_bracketed_end_of_line_comment(comment, locator)
|
||||
} else {
|
||||
CommentPlacement::Default(comment)
|
||||
}
|
||||
}
|
||||
AnyNodeRef::ExprAttribute(attribute) => {
|
||||
handle_attribute_comment(comment, attribute, locator)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue