Add support for trailing colons in slice expressions (#3077)
This commit is contained in:
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user