mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 16:40:36 +00:00
Add as_slice
method for all string nodes (#9111)
This PR adds a `as_slice` method to all the string nodes which returns all the parts of the nodes as a slice. This will be useful in the next PR to split the string formatting to use this method to extract the _single node_ or _implicitly concanated nodes_.
This commit is contained in:
parent
cb99815c3e
commit
18452cf477
13 changed files with 121 additions and 65 deletions
|
@ -583,10 +583,10 @@ impl<'a> From<ast::LiteralExpressionRef<'a>> for ComparableLiteral<'a> {
|
|||
value, ..
|
||||
}) => Self::Bool(value),
|
||||
ast::LiteralExpressionRef::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
|
||||
Self::Str(value.parts().map(Into::into).collect())
|
||||
Self::Str(value.iter().map(Into::into).collect())
|
||||
}
|
||||
ast::LiteralExpressionRef::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => {
|
||||
Self::Bytes(value.parts().map(Into::into).collect())
|
||||
Self::Bytes(value.iter().map(Into::into).collect())
|
||||
}
|
||||
ast::LiteralExpressionRef::NumberLiteral(ast::ExprNumberLiteral { value, .. }) => {
|
||||
Self::Number(value.into())
|
||||
|
@ -1012,17 +1012,17 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
}),
|
||||
ast::Expr::FString(ast::ExprFString { value, range: _ }) => {
|
||||
Self::FString(ExprFString {
|
||||
parts: value.parts().map(Into::into).collect(),
|
||||
parts: value.iter().map(Into::into).collect(),
|
||||
})
|
||||
}
|
||||
ast::Expr::StringLiteral(ast::ExprStringLiteral { value, range: _ }) => {
|
||||
Self::StringLiteral(ExprStringLiteral {
|
||||
parts: value.parts().map(Into::into).collect(),
|
||||
parts: value.iter().map(Into::into).collect(),
|
||||
})
|
||||
}
|
||||
ast::Expr::BytesLiteral(ast::ExprBytesLiteral { value, range: _ }) => {
|
||||
Self::BytesLiteral(ExprBytesLiteral {
|
||||
parts: value.parts().map(Into::into).collect(),
|
||||
parts: value.iter().map(Into::into).collect(),
|
||||
})
|
||||
}
|
||||
ast::Expr::NumberLiteral(ast::ExprNumberLiteral { value, range: _ }) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue