mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Add support for trailing colons in slice expressions (#3077)
This commit is contained in:
parent
7d4e513a82
commit
ce8953442d
5 changed files with 29 additions and 2 deletions
|
@ -22,6 +22,10 @@ impl Format<ASTFormatContext<'_>> for FormatComprehension<'_> {
|
|||
let comprehension = self.item;
|
||||
|
||||
write!(f, [soft_line_break_or_space()])?;
|
||||
if comprehension.is_async > 0 {
|
||||
write!(f, [text("async")])?;
|
||||
write!(f, [space()])?;
|
||||
}
|
||||
write!(f, [text("for")])?;
|
||||
write!(f, [space()])?;
|
||||
// TODO(charlie): If this is an unparenthesized tuple, we need to avoid expanding it.
|
||||
|
|
|
@ -218,6 +218,17 @@ fn format_slice(
|
|||
write!(f, [space()])?;
|
||||
}
|
||||
write!(f, [step.format()])?;
|
||||
} else {
|
||||
let magic_trailing_colon = expr
|
||||
.trivia
|
||||
.iter()
|
||||
.any(|c| matches!(c.kind, TriviaKind::MagicTrailingColon));
|
||||
if magic_trailing_colon {
|
||||
if !is_simple && upper.is_some() {
|
||||
write!(f, [space()])?;
|
||||
}
|
||||
write!(f, [text(":")])?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue