Add support for trailing colons in slice expressions (#3077)

This commit is contained in:
Charlie Marsh 2023-02-20 18:24:32 -05:00 committed by GitHub
parent 7d4e513a82
commit ce8953442d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 2 deletions

View file

@ -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.

View file

@ -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(())