mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Avoid searching for bracketed comments in unparenthesized generators (#7627)
Similar to tuples, a generator _can_ be parenthesized or unparenthesized. Only search for bracketed comments if it contains its own parentheses. Closes https://github.com/astral-sh/ruff/issues/7623.
This commit is contained in:
parent
1a22eae98c
commit
865c89800e
5 changed files with 66 additions and 7 deletions
|
@ -11,6 +11,7 @@ use ruff_source_file::Locator;
|
|||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::comments::visitor::{CommentPlacement, DecoratedComment};
|
||||
use crate::expression::expr_generator_exp::is_generator_parenthesized;
|
||||
use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
|
||||
use crate::expression::expr_tuple::is_tuple_parenthesized;
|
||||
use crate::other::parameters::{
|
||||
|
@ -290,12 +291,16 @@ fn handle_enclosed_comment<'a>(
|
|||
AnyNodeRef::ExprFString(fstring) => CommentPlacement::dangling(fstring, comment),
|
||||
AnyNodeRef::ExprList(_)
|
||||
| AnyNodeRef::ExprSet(_)
|
||||
| AnyNodeRef::ExprGeneratorExp(_)
|
||||
| AnyNodeRef::ExprListComp(_)
|
||||
| AnyNodeRef::ExprSetComp(_) => handle_bracketed_end_of_line_comment(comment, locator),
|
||||
AnyNodeRef::ExprTuple(tuple) if is_tuple_parenthesized(tuple, locator.contents()) => {
|
||||
handle_bracketed_end_of_line_comment(comment, locator)
|
||||
}
|
||||
AnyNodeRef::ExprGeneratorExp(generator)
|
||||
if is_generator_parenthesized(generator, locator.contents()) =>
|
||||
{
|
||||
handle_bracketed_end_of_line_comment(comment, locator)
|
||||
}
|
||||
_ => CommentPlacement::Default(comment),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue