Rename JoinedStr to FString in the AST (#6379)

## Summary

Per the proposal in https://github.com/astral-sh/ruff/discussions/6183,
this PR renames the `JoinedStr` node to `FString`.
This commit is contained in:
Charlie Marsh 2023-08-07 13:33:17 -04:00 committed by GitHub
parent 999d88e773
commit 3f0eea6d87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 166 additions and 166 deletions

View file

@ -923,7 +923,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
pylint::rules::await_outside_async(checker, expr); pylint::rules::await_outside_async(checker, expr);
} }
} }
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
if checker.enabled(Rule::FStringMissingPlaceholders) { if checker.enabled(Rule::FStringMissingPlaceholders) {
pyflakes::rules::f_string_missing_placeholders(expr, values, checker); pyflakes::rules::f_string_missing_placeholders(expr, values, checker);
} }

View file

@ -1197,7 +1197,7 @@ where
)); ));
} }
} }
Expr::JoinedStr(_) => { Expr::FString(_) => {
self.semantic.flags |= SemanticModelFlags::F_STRING; self.semantic.flags |= SemanticModelFlags::F_STRING;
visitor::walk_expr(self, expr); visitor::walk_expr(self, expr);
} }
@ -1276,7 +1276,7 @@ where
fn visit_format_spec(&mut self, format_spec: &'b Expr) { fn visit_format_spec(&mut self, format_spec: &'b Expr) {
match format_spec { match format_spec {
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
for value in values { for value in values {
self.visit_expr(value); self.visit_expr(value);
} }

View file

@ -80,7 +80,7 @@ fn matches_string_format_expression(expr: &Expr, model: &SemanticModel) -> bool
attr == "format" && string_literal(value).is_some() attr == "format" && string_literal(value).is_some()
} }
// f"select * from table where val = {val}" // f"select * from table where val = {val}"
Expr::JoinedStr(_) => true, Expr::FString(_) => true,
_ => false, _ => false,
} }
} }

View file

@ -50,7 +50,7 @@ pub(crate) fn f_string_docstring(checker: &mut Checker, body: &[Stmt]) {
let Stmt::Expr(ast::StmtExpr { value, range: _ }) = stmt else { let Stmt::Expr(ast::StmtExpr { value, range: _ }) = stmt else {
return; return;
}; };
if !value.is_joined_str_expr() { if !value.is_f_string_expr() {
return; return;
} }
checker checker

View file

@ -54,7 +54,7 @@ pub(crate) fn useless_expression(checker: &mut Checker, value: &Expr) {
// Ignore strings, to avoid false positives with docstrings. // Ignore strings, to avoid false positives with docstrings.
if matches!( if matches!(
value, value,
Expr::JoinedStr(_) Expr::FString(_)
| Expr::Constant(ast::ExprConstant { | Expr::Constant(ast::ExprConstant {
value: Constant::Str(..) | Constant::Ellipsis, value: Constant::Str(..) | Constant::Ellipsis,
.. ..

View file

@ -210,7 +210,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr
} }
} }
// Check for f-strings. // Check for f-strings.
Expr::JoinedStr(_) => { Expr::FString(_) => {
if checker.enabled(Rule::FStringInException) { if checker.enabled(Rule::FStringInException) {
let mut diagnostic = Diagnostic::new(FStringInException, first.range()); let mut diagnostic = Diagnostic::new(FStringInException, first.range());
if checker.patch(diagnostic.kind.rule()) { if checker.patch(diagnostic.kind.rule()) {

View file

@ -52,7 +52,7 @@ impl Violation for FStringInGetTextFuncCall {
/// INT001 /// INT001
pub(crate) fn f_string_in_gettext_func_call(checker: &mut Checker, args: &[Expr]) { pub(crate) fn f_string_in_gettext_func_call(checker: &mut Checker, args: &[Expr]) {
if let Some(first) = args.first() { if let Some(first) = args.first() {
if first.is_joined_str_expr() { if first.is_f_string_expr() {
checker checker
.diagnostics .diagnostics
.push(Diagnostic::new(FStringInGetTextFuncCall {}, first.range())); .push(Diagnostic::new(FStringInGetTextFuncCall {}, first.range()));

View file

@ -50,14 +50,14 @@ pub(crate) fn explicit(expr: &Expr, locator: &Locator) -> Option<Diagnostic> {
if matches!(op, Operator::Add) { if matches!(op, Operator::Add) {
if matches!( if matches!(
left.as_ref(), left.as_ref(),
Expr::JoinedStr(_) Expr::FString(_)
| Expr::Constant(ast::ExprConstant { | Expr::Constant(ast::ExprConstant {
value: Constant::Str(..) | Constant::Bytes(..), value: Constant::Str(..) | Constant::Bytes(..),
.. ..
}) })
) && matches!( ) && matches!(
right.as_ref(), right.as_ref(),
Expr::JoinedStr(_) Expr::FString(_)
| Expr::Constant(ast::ExprConstant { | Expr::Constant(ast::ExprConstant {
value: Constant::Str(..) | Constant::Bytes(..), value: Constant::Str(..) | Constant::Bytes(..),
.. ..

View file

@ -62,7 +62,7 @@ fn check_msg(checker: &mut Checker, msg: &Expr) {
_ => {} _ => {}
}, },
// Check for f-strings. // Check for f-strings.
Expr::JoinedStr(_) => { Expr::FString(_) => {
if checker.enabled(Rule::LoggingFString) { if checker.enabled(Rule::LoggingFString) {
checker checker
.diagnostics .diagnostics

View file

@ -63,7 +63,7 @@ pub(super) fn is_empty_or_null_string(expr: &Expr) -> bool {
.. ..
}) => string.is_empty(), }) => string.is_empty(),
Expr::Constant(constant) if constant.value.is_none() => true, Expr::Constant(constant) if constant.value.is_none() => true,
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
values.iter().all(is_empty_or_null_string) values.iter().all(is_empty_or_null_string)
} }
_ => false, _ => false,

View file

@ -52,14 +52,14 @@ fn is_simple_callee(func: &Expr) -> bool {
} }
/// Convert an expression to a f-string element (if it looks like a good idea). /// Convert an expression to a f-string element (if it looks like a good idea).
pub(super) fn to_fstring_elem(expr: &Expr) -> Option<Expr> { pub(super) fn to_f_string_element(expr: &Expr) -> Option<Expr> {
match expr { match expr {
// These are directly handled by `unparse_fstring_elem`: // These are directly handled by `unparse_f_string_element`:
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {
value: Constant::Str(_), value: Constant::Str(_),
.. ..
}) })
| Expr::JoinedStr(_) | Expr::FString(_)
| Expr::FormattedValue(_) => Some(expr.clone()), | Expr::FormattedValue(_) => Some(expr.clone()),
// These should be pretty safe to wrap in a formatted value. // These should be pretty safe to wrap in a formatted value.
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {

View file

@ -87,7 +87,7 @@ fn build_fstring(joiner: &str, joinees: &[Expr]) -> Option<Expr> {
let mut first = true; let mut first = true;
for expr in joinees { for expr in joinees {
if expr.is_joined_str_expr() { if expr.is_f_string_expr() {
// Oops, already an f-string. We don't know how to handle those // Oops, already an f-string. We don't know how to handle those
// gracefully right now. // gracefully right now.
return None; return None;
@ -95,10 +95,10 @@ fn build_fstring(joiner: &str, joinees: &[Expr]) -> Option<Expr> {
if !std::mem::take(&mut first) { if !std::mem::take(&mut first) {
fstring_elems.push(helpers::to_constant_string(joiner)); fstring_elems.push(helpers::to_constant_string(joiner));
} }
fstring_elems.push(helpers::to_fstring_elem(expr)?); fstring_elems.push(helpers::to_f_string_element(expr)?);
} }
let node = ast::ExprJoinedStr { let node = ast::ExprFString {
values: fstring_elems, values: fstring_elems,
range: TextRange::default(), range: TextRange::default(),
}; };

View file

@ -48,7 +48,7 @@ impl AlwaysAutofixableViolation for FStringMissingPlaceholders {
} }
} }
/// Find f-strings that don't contain any formatted values in a `JoinedStr`. /// Find f-strings that don't contain any formatted values in an [`FString`].
fn find_useless_f_strings<'a>( fn find_useless_f_strings<'a>(
expr: &'a Expr, expr: &'a Expr,
locator: &'a Locator, locator: &'a Locator,

View file

@ -130,7 +130,7 @@ pub(crate) fn repeated_keys(checker: &mut Checker, keys: &[Option<Expr>], values
}; };
match key { match key {
Expr::Constant(_) | Expr::Tuple(_) | Expr::JoinedStr(_) => { Expr::Constant(_) | Expr::Tuple(_) | Expr::FString(_) => {
if checker.enabled(Rule::MultiValueRepeatedKeyLiteral) { if checker.enabled(Rule::MultiValueRepeatedKeyLiteral) {
let mut diagnostic = Diagnostic::new( let mut diagnostic = Diagnostic::new(
MultiValueRepeatedKeyLiteral { MultiValueRepeatedKeyLiteral {

View file

@ -71,7 +71,7 @@ pub(crate) fn assert_on_string_literal(checker: &mut Checker, test: &Expr) {
} }
_ => {} _ => {}
}, },
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
checker.diagnostics.push(Diagnostic::new( checker.diagnostics.push(Diagnostic::new(
AssertOnStringLiteral { AssertOnStringLiteral {
kind: if values.iter().all(|value| match value { kind: if values.iter().all(|value| match value {

View file

@ -71,7 +71,7 @@ fn is_valid_default(expr: &Expr) -> bool {
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {
value: Constant::Str { .. } | Constant::None { .. }, value: Constant::Str { .. } | Constant::None { .. },
.. ..
}) | Expr::JoinedStr(_) }) | Expr::FString(_)
) )
} }

View file

@ -68,7 +68,7 @@ fn is_valid_key(expr: &Expr) -> bool {
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {
value: Constant::Str { .. }, value: Constant::Str { .. },
.. ..
}) | Expr::JoinedStr(_) }) | Expr::FString(_)
) )
} }

View file

@ -70,7 +70,7 @@ pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) {
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {
value: Constant::Str(_), value: Constant::Str(_),
.. ..
}) | Expr::JoinedStr(_) }) | Expr::FString(_)
) { ) {
checker checker
.diagnostics .diagnostics
@ -92,7 +92,7 @@ pub(crate) fn single_string_slots(checker: &mut Checker, class: &StmtClassDef) {
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {
value: Constant::Str(_), value: Constant::Str(_),
.. ..
}) | Expr::JoinedStr(_) }) | Expr::FString(_)
) { ) {
checker checker
.diagnostics .diagnostics

View file

@ -150,7 +150,7 @@ pub(crate) fn native_literals(
if checker if checker
.semantic() .semantic()
.current_expressions() .current_expressions()
.filter(|expr| expr.is_joined_str_expr()) .filter(|expr| expr.is_f_string_expr())
.count() .count()
> 1 > 1
{ {

View file

@ -400,7 +400,7 @@ pub(crate) fn printf_string_formatting(
// Parse the parameters. // Parse the parameters.
let params_string = match right { let params_string = match right {
Expr::Constant(_) | Expr::JoinedStr(_) => { Expr::Constant(_) | Expr::FString(_) => {
format!("({})", checker.locator().slice(right.range())) format!("({})", checker.locator().slice(right.range()))
} }
Expr::Name(_) | Expr::Attribute(_) | Expr::Subscript(_) | Expr::Call(_) => { Expr::Name(_) | Expr::Attribute(_) | Expr::Subscript(_) | Expr::Call(_) => {

View file

@ -226,7 +226,7 @@ pub(crate) fn unnecessary_encode_utf8(checker: &mut Checker, call: &ast::ExprCal
} }
} }
// Ex) `f"foo{bar}".encode("utf-8")` // Ex) `f"foo{bar}".encode("utf-8")`
Expr::JoinedStr(_) => { Expr::FString(_) => {
if let Some(encoding_arg) = match_encoding_arg(&call.arguments) { if let Some(encoding_arg) = match_encoding_arg(&call.arguments) {
if let EncodingArg::Keyword(kwarg) = encoding_arg { if let EncodingArg::Keyword(kwarg) = encoding_arg {
// Ex) Convert `f"unicode text©".encode(encoding="utf-8")` to // Ex) Convert `f"unicode text©".encode(encoding="utf-8")` to

View file

@ -63,7 +63,7 @@ pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) {
Expr::List(_) Expr::List(_)
| Expr::ListComp(_) | Expr::ListComp(_)
| Expr::Tuple(_) | Expr::Tuple(_)
| Expr::JoinedStr(_) | Expr::FString(_)
| Expr::Constant(ExprConstant { | Expr::Constant(ExprConstant {
value: Constant::Str(_) | Constant::Bytes(_), value: Constant::Str(_) | Constant::Bytes(_),
.. ..
@ -156,7 +156,7 @@ pub(crate) fn invalid_index_type(checker: &mut Checker, expr: &ExprSubscript) {
#[derive(Debug)] #[derive(Debug)]
enum CheckableExprType<'a> { enum CheckableExprType<'a> {
Constant(&'a Constant), Constant(&'a Constant),
JoinedStr, FString,
List, List,
ListComp, ListComp,
SetComp, SetComp,
@ -171,7 +171,7 @@ impl fmt::Display for CheckableExprType<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Self::Constant(constant) => f.write_str(constant_type_name(constant)), Self::Constant(constant) => f.write_str(constant_type_name(constant)),
Self::JoinedStr => f.write_str("str"), Self::FString => f.write_str("str"),
Self::List => f.write_str("list"), Self::List => f.write_str("list"),
Self::SetComp => f.write_str("set comprehension"), Self::SetComp => f.write_str("set comprehension"),
Self::ListComp => f.write_str("list comprehension"), Self::ListComp => f.write_str("list comprehension"),
@ -188,7 +188,7 @@ impl<'a> CheckableExprType<'a> {
fn try_from(expr: &'a Expr) -> Option<Self> { fn try_from(expr: &'a Expr) -> Option<Self> {
match expr { match expr {
Expr::Constant(ExprConstant { value, .. }) => Some(Self::Constant(value)), Expr::Constant(ExprConstant { value, .. }) => Some(Self::Constant(value)),
Expr::JoinedStr(_) => Some(Self::JoinedStr), Expr::FString(_) => Some(Self::FString),
Expr::List(_) => Some(Self::List), Expr::List(_) => Some(Self::List),
Expr::ListComp(_) => Some(Self::ListComp), Expr::ListComp(_) => Some(Self::ListComp),
Expr::SetComp(_) => Some(Self::SetComp), Expr::SetComp(_) => Some(Self::SetComp),

View file

@ -633,7 +633,7 @@ impl<'stmt> BasicBlocksBuilder<'stmt> {
| Expr::Compare(_) | Expr::Compare(_)
| Expr::Call(_) | Expr::Call(_)
| Expr::FormattedValue(_) | Expr::FormattedValue(_)
| Expr::JoinedStr(_) | Expr::FString(_)
| Expr::Constant(_) | Expr::Constant(_)
| Expr::Attribute(_) | Expr::Attribute(_)
| Expr::Subscript(_) | Expr::Subscript(_)

View file

@ -54,7 +54,7 @@ where
F: (Fn(&str) -> bool) + Copy, F: (Fn(&str) -> bool) + Copy,
{ {
match expr { match expr {
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
for value in values { for value in values {
if any_string(value, predicate) { if any_string(value, predicate) {
return true; return true;

View file

@ -616,7 +616,7 @@ pub struct ExprFormattedValue<'a> {
} }
#[derive(Debug, PartialEq, Eq, Hash)] #[derive(Debug, PartialEq, Eq, Hash)]
pub struct ExprJoinedStr<'a> { pub struct ExprFString<'a> {
values: Vec<ComparableExpr<'a>>, values: Vec<ComparableExpr<'a>>,
} }
@ -697,7 +697,7 @@ pub enum ComparableExpr<'a> {
Compare(ExprCompare<'a>), Compare(ExprCompare<'a>),
Call(ExprCall<'a>), Call(ExprCall<'a>),
FormattedValue(ExprFormattedValue<'a>), FormattedValue(ExprFormattedValue<'a>),
JoinedStr(ExprJoinedStr<'a>), FString(ExprFString<'a>),
Constant(ExprConstant<'a>), Constant(ExprConstant<'a>),
Attribute(ExprAttribute<'a>), Attribute(ExprAttribute<'a>),
Subscript(ExprSubscript<'a>), Subscript(ExprSubscript<'a>),
@ -865,8 +865,8 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
debug_text: debug_text.as_ref(), debug_text: debug_text.as_ref(),
format_spec: format_spec.as_ref().map(Into::into), format_spec: format_spec.as_ref().map(Into::into),
}), }),
ast::Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { ast::Expr::FString(ast::ExprFString { values, range: _ }) => {
Self::JoinedStr(ExprJoinedStr { Self::FString(ExprFString {
values: values.iter().map(Into::into).collect(), values: values.iter().map(Into::into).collect(),
}) })
} }

View file

@ -68,7 +68,7 @@ where
if !matches!( if !matches!(
left.as_ref(), left.as_ref(),
Expr::Constant(_) Expr::Constant(_)
| Expr::JoinedStr(_) | Expr::FString(_)
| Expr::List(_) | Expr::List(_)
| Expr::Tuple(_) | Expr::Tuple(_)
| Expr::Set(_) | Expr::Set(_)
@ -82,7 +82,7 @@ where
if !matches!( if !matches!(
right.as_ref(), right.as_ref(),
Expr::Constant(_) Expr::Constant(_)
| Expr::JoinedStr(_) | Expr::FString(_)
| Expr::List(_) | Expr::List(_)
| Expr::Tuple(_) | Expr::Tuple(_)
| Expr::Set(_) | Expr::Set(_)
@ -126,7 +126,7 @@ where
Expr::BoolOp(ast::ExprBoolOp { Expr::BoolOp(ast::ExprBoolOp {
values, range: _, .. values, range: _, ..
}) })
| Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { | Expr::FString(ast::ExprFString { values, range: _ }) => {
values.iter().any(|expr| any_over_expr(expr, func)) values.iter().any(|expr| any_over_expr(expr, func))
} }
Expr::NamedExpr(ast::ExprNamedExpr { Expr::NamedExpr(ast::ExprNamedExpr {
@ -1094,7 +1094,7 @@ impl Truthiness {
Constant::Complex { real, imag } => Some(*real != 0.0 || *imag != 0.0), Constant::Complex { real, imag } => Some(*real != 0.0 || *imag != 0.0),
Constant::Ellipsis => Some(true), Constant::Ellipsis => Some(true),
}, },
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
if values.is_empty() { if values.is_empty() {
Some(false) Some(false)
} else if values.iter().any(|value| { } else if values.iter().any(|value| {

View file

@ -67,7 +67,7 @@ pub enum AnyNode {
ExprCompare(ast::ExprCompare), ExprCompare(ast::ExprCompare),
ExprCall(ast::ExprCall), ExprCall(ast::ExprCall),
ExprFormattedValue(ast::ExprFormattedValue), ExprFormattedValue(ast::ExprFormattedValue),
ExprJoinedStr(ast::ExprJoinedStr), ExprFString(ast::ExprFString),
ExprConstant(ast::ExprConstant), ExprConstant(ast::ExprConstant),
ExprAttribute(ast::ExprAttribute), ExprAttribute(ast::ExprAttribute),
ExprSubscript(ast::ExprSubscript), ExprSubscript(ast::ExprSubscript),
@ -153,7 +153,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_) | AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_) | AnyNode::ExprCall(_)
| AnyNode::ExprFormattedValue(_) | AnyNode::ExprFormattedValue(_)
| AnyNode::ExprJoinedStr(_) | AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_) | AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_) | AnyNode::ExprAttribute(_)
| AnyNode::ExprSubscript(_) | AnyNode::ExprSubscript(_)
@ -210,7 +210,7 @@ impl AnyNode {
AnyNode::ExprCompare(node) => Some(Expr::Compare(node)), AnyNode::ExprCompare(node) => Some(Expr::Compare(node)),
AnyNode::ExprCall(node) => Some(Expr::Call(node)), AnyNode::ExprCall(node) => Some(Expr::Call(node)),
AnyNode::ExprFormattedValue(node) => Some(Expr::FormattedValue(node)), AnyNode::ExprFormattedValue(node) => Some(Expr::FormattedValue(node)),
AnyNode::ExprJoinedStr(node) => Some(Expr::JoinedStr(node)), AnyNode::ExprFString(node) => Some(Expr::FString(node)),
AnyNode::ExprConstant(node) => Some(Expr::Constant(node)), AnyNode::ExprConstant(node) => Some(Expr::Constant(node)),
AnyNode::ExprAttribute(node) => Some(Expr::Attribute(node)), AnyNode::ExprAttribute(node) => Some(Expr::Attribute(node)),
AnyNode::ExprSubscript(node) => Some(Expr::Subscript(node)), AnyNode::ExprSubscript(node) => Some(Expr::Subscript(node)),
@ -325,7 +325,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_) | AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_) | AnyNode::ExprCall(_)
| AnyNode::ExprFormattedValue(_) | AnyNode::ExprFormattedValue(_)
| AnyNode::ExprJoinedStr(_) | AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_) | AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_) | AnyNode::ExprAttribute(_)
| AnyNode::ExprSubscript(_) | AnyNode::ExprSubscript(_)
@ -419,7 +419,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_) | AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_) | AnyNode::ExprCall(_)
| AnyNode::ExprFormattedValue(_) | AnyNode::ExprFormattedValue(_)
| AnyNode::ExprJoinedStr(_) | AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_) | AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_) | AnyNode::ExprAttribute(_)
| AnyNode::ExprSubscript(_) | AnyNode::ExprSubscript(_)
@ -498,7 +498,7 @@ impl AnyNode {
| AnyNode::ExprCompare(_) | AnyNode::ExprCompare(_)
| AnyNode::ExprCall(_) | AnyNode::ExprCall(_)
| AnyNode::ExprFormattedValue(_) | AnyNode::ExprFormattedValue(_)
| AnyNode::ExprJoinedStr(_) | AnyNode::ExprFString(_)
| AnyNode::ExprConstant(_) | AnyNode::ExprConstant(_)
| AnyNode::ExprAttribute(_) | AnyNode::ExprAttribute(_)
| AnyNode::ExprSubscript(_) | AnyNode::ExprSubscript(_)
@ -602,7 +602,7 @@ impl AnyNode {
Self::ExprCompare(node) => AnyNodeRef::ExprCompare(node), Self::ExprCompare(node) => AnyNodeRef::ExprCompare(node),
Self::ExprCall(node) => AnyNodeRef::ExprCall(node), Self::ExprCall(node) => AnyNodeRef::ExprCall(node),
Self::ExprFormattedValue(node) => AnyNodeRef::ExprFormattedValue(node), Self::ExprFormattedValue(node) => AnyNodeRef::ExprFormattedValue(node),
Self::ExprJoinedStr(node) => AnyNodeRef::ExprJoinedStr(node), Self::ExprFString(node) => AnyNodeRef::ExprFString(node),
Self::ExprConstant(node) => AnyNodeRef::ExprConstant(node), Self::ExprConstant(node) => AnyNodeRef::ExprConstant(node),
Self::ExprAttribute(node) => AnyNodeRef::ExprAttribute(node), Self::ExprAttribute(node) => AnyNodeRef::ExprAttribute(node),
Self::ExprSubscript(node) => AnyNodeRef::ExprSubscript(node), Self::ExprSubscript(node) => AnyNodeRef::ExprSubscript(node),
@ -1961,12 +1961,12 @@ impl AstNode for ast::ExprFormattedValue {
AnyNode::from(self) AnyNode::from(self)
} }
} }
impl AstNode for ast::ExprJoinedStr { impl AstNode for ast::ExprFString {
fn cast(kind: AnyNode) -> Option<Self> fn cast(kind: AnyNode) -> Option<Self>
where where
Self: Sized, Self: Sized,
{ {
if let AnyNode::ExprJoinedStr(node) = kind { if let AnyNode::ExprFString(node) = kind {
Some(node) Some(node)
} else { } else {
None None
@ -1974,7 +1974,7 @@ impl AstNode for ast::ExprJoinedStr {
} }
fn cast_ref(kind: AnyNodeRef) -> Option<&Self> { fn cast_ref(kind: AnyNodeRef) -> Option<&Self> {
if let AnyNodeRef::ExprJoinedStr(node) = kind { if let AnyNodeRef::ExprFString(node) = kind {
Some(node) Some(node)
} else { } else {
None None
@ -2941,7 +2941,7 @@ impl From<Expr> for AnyNode {
Expr::Compare(node) => AnyNode::ExprCompare(node), Expr::Compare(node) => AnyNode::ExprCompare(node),
Expr::Call(node) => AnyNode::ExprCall(node), Expr::Call(node) => AnyNode::ExprCall(node),
Expr::FormattedValue(node) => AnyNode::ExprFormattedValue(node), Expr::FormattedValue(node) => AnyNode::ExprFormattedValue(node),
Expr::JoinedStr(node) => AnyNode::ExprJoinedStr(node), Expr::FString(node) => AnyNode::ExprFString(node),
Expr::Constant(node) => AnyNode::ExprConstant(node), Expr::Constant(node) => AnyNode::ExprConstant(node),
Expr::Attribute(node) => AnyNode::ExprAttribute(node), Expr::Attribute(node) => AnyNode::ExprAttribute(node),
Expr::Subscript(node) => AnyNode::ExprSubscript(node), Expr::Subscript(node) => AnyNode::ExprSubscript(node),
@ -3269,9 +3269,9 @@ impl From<ast::ExprFormattedValue> for AnyNode {
} }
} }
impl From<ast::ExprJoinedStr> for AnyNode { impl From<ast::ExprFString> for AnyNode {
fn from(node: ast::ExprJoinedStr) -> Self { fn from(node: ast::ExprFString) -> Self {
AnyNode::ExprJoinedStr(node) AnyNode::ExprFString(node)
} }
} }
@ -3505,7 +3505,7 @@ impl Ranged for AnyNode {
AnyNode::ExprCompare(node) => node.range(), AnyNode::ExprCompare(node) => node.range(),
AnyNode::ExprCall(node) => node.range(), AnyNode::ExprCall(node) => node.range(),
AnyNode::ExprFormattedValue(node) => node.range(), AnyNode::ExprFormattedValue(node) => node.range(),
AnyNode::ExprJoinedStr(node) => node.range(), AnyNode::ExprFString(node) => node.range(),
AnyNode::ExprConstant(node) => node.range(), AnyNode::ExprConstant(node) => node.range(),
AnyNode::ExprAttribute(node) => node.range(), AnyNode::ExprAttribute(node) => node.range(),
AnyNode::ExprSubscript(node) => node.range(), AnyNode::ExprSubscript(node) => node.range(),
@ -3591,7 +3591,7 @@ pub enum AnyNodeRef<'a> {
ExprCompare(&'a ast::ExprCompare), ExprCompare(&'a ast::ExprCompare),
ExprCall(&'a ast::ExprCall), ExprCall(&'a ast::ExprCall),
ExprFormattedValue(&'a ast::ExprFormattedValue), ExprFormattedValue(&'a ast::ExprFormattedValue),
ExprJoinedStr(&'a ast::ExprJoinedStr), ExprFString(&'a ast::ExprFString),
ExprConstant(&'a ast::ExprConstant), ExprConstant(&'a ast::ExprConstant),
ExprAttribute(&'a ast::ExprAttribute), ExprAttribute(&'a ast::ExprAttribute),
ExprSubscript(&'a ast::ExprSubscript), ExprSubscript(&'a ast::ExprSubscript),
@ -3676,7 +3676,7 @@ impl AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprCompare(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprCall(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprCall(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprFormattedValue(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprFormattedValue(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprJoinedStr(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprFString(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprConstant(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprConstant(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprAttribute(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprAttribute(node) => NonNull::from(*node).cast(),
AnyNodeRef::ExprSubscript(node) => NonNull::from(*node).cast(), AnyNodeRef::ExprSubscript(node) => NonNull::from(*node).cast(),
@ -3767,7 +3767,7 @@ impl AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(_) => NodeKind::ExprCompare, AnyNodeRef::ExprCompare(_) => NodeKind::ExprCompare,
AnyNodeRef::ExprCall(_) => NodeKind::ExprCall, AnyNodeRef::ExprCall(_) => NodeKind::ExprCall,
AnyNodeRef::ExprFormattedValue(_) => NodeKind::ExprFormattedValue, AnyNodeRef::ExprFormattedValue(_) => NodeKind::ExprFormattedValue,
AnyNodeRef::ExprJoinedStr(_) => NodeKind::ExprJoinedStr, AnyNodeRef::ExprFString(_) => NodeKind::ExprFString,
AnyNodeRef::ExprConstant(_) => NodeKind::ExprConstant, AnyNodeRef::ExprConstant(_) => NodeKind::ExprConstant,
AnyNodeRef::ExprAttribute(_) => NodeKind::ExprAttribute, AnyNodeRef::ExprAttribute(_) => NodeKind::ExprAttribute,
AnyNodeRef::ExprSubscript(_) => NodeKind::ExprSubscript, AnyNodeRef::ExprSubscript(_) => NodeKind::ExprSubscript,
@ -3853,7 +3853,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_) | AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_) | AnyNodeRef::ExprCall(_)
| AnyNodeRef::ExprFormattedValue(_) | AnyNodeRef::ExprFormattedValue(_)
| AnyNodeRef::ExprJoinedStr(_) | AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_) | AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_) | AnyNodeRef::ExprAttribute(_)
| AnyNodeRef::ExprSubscript(_) | AnyNodeRef::ExprSubscript(_)
@ -3910,7 +3910,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_) | AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_) | AnyNodeRef::ExprCall(_)
| AnyNodeRef::ExprFormattedValue(_) | AnyNodeRef::ExprFormattedValue(_)
| AnyNodeRef::ExprJoinedStr(_) | AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_) | AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_) | AnyNodeRef::ExprAttribute(_)
| AnyNodeRef::ExprSubscript(_) | AnyNodeRef::ExprSubscript(_)
@ -4024,7 +4024,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_) | AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_) | AnyNodeRef::ExprCall(_)
| AnyNodeRef::ExprFormattedValue(_) | AnyNodeRef::ExprFormattedValue(_)
| AnyNodeRef::ExprJoinedStr(_) | AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_) | AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_) | AnyNodeRef::ExprAttribute(_)
| AnyNodeRef::ExprSubscript(_) | AnyNodeRef::ExprSubscript(_)
@ -4118,7 +4118,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_) | AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_) | AnyNodeRef::ExprCall(_)
| AnyNodeRef::ExprFormattedValue(_) | AnyNodeRef::ExprFormattedValue(_)
| AnyNodeRef::ExprJoinedStr(_) | AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_) | AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_) | AnyNodeRef::ExprAttribute(_)
| AnyNodeRef::ExprSubscript(_) | AnyNodeRef::ExprSubscript(_)
@ -4197,7 +4197,7 @@ impl AnyNodeRef<'_> {
| AnyNodeRef::ExprCompare(_) | AnyNodeRef::ExprCompare(_)
| AnyNodeRef::ExprCall(_) | AnyNodeRef::ExprCall(_)
| AnyNodeRef::ExprFormattedValue(_) | AnyNodeRef::ExprFormattedValue(_)
| AnyNodeRef::ExprJoinedStr(_) | AnyNodeRef::ExprFString(_)
| AnyNodeRef::ExprConstant(_) | AnyNodeRef::ExprConstant(_)
| AnyNodeRef::ExprAttribute(_) | AnyNodeRef::ExprAttribute(_)
| AnyNodeRef::ExprSubscript(_) | AnyNodeRef::ExprSubscript(_)
@ -4543,9 +4543,9 @@ impl<'a> From<&'a ast::ExprFormattedValue> for AnyNodeRef<'a> {
} }
} }
impl<'a> From<&'a ast::ExprJoinedStr> for AnyNodeRef<'a> { impl<'a> From<&'a ast::ExprFString> for AnyNodeRef<'a> {
fn from(node: &'a ast::ExprJoinedStr) -> Self { fn from(node: &'a ast::ExprFString) -> Self {
AnyNodeRef::ExprJoinedStr(node) AnyNodeRef::ExprFString(node)
} }
} }
@ -4740,7 +4740,7 @@ impl<'a> From<&'a Expr> for AnyNodeRef<'a> {
Expr::Compare(node) => AnyNodeRef::ExprCompare(node), Expr::Compare(node) => AnyNodeRef::ExprCompare(node),
Expr::Call(node) => AnyNodeRef::ExprCall(node), Expr::Call(node) => AnyNodeRef::ExprCall(node),
Expr::FormattedValue(node) => AnyNodeRef::ExprFormattedValue(node), Expr::FormattedValue(node) => AnyNodeRef::ExprFormattedValue(node),
Expr::JoinedStr(node) => AnyNodeRef::ExprJoinedStr(node), Expr::FString(node) => AnyNodeRef::ExprFString(node),
Expr::Constant(node) => AnyNodeRef::ExprConstant(node), Expr::Constant(node) => AnyNodeRef::ExprConstant(node),
Expr::Attribute(node) => AnyNodeRef::ExprAttribute(node), Expr::Attribute(node) => AnyNodeRef::ExprAttribute(node),
Expr::Subscript(node) => AnyNodeRef::ExprSubscript(node), Expr::Subscript(node) => AnyNodeRef::ExprSubscript(node),
@ -4893,7 +4893,7 @@ impl Ranged for AnyNodeRef<'_> {
AnyNodeRef::ExprCompare(node) => node.range(), AnyNodeRef::ExprCompare(node) => node.range(),
AnyNodeRef::ExprCall(node) => node.range(), AnyNodeRef::ExprCall(node) => node.range(),
AnyNodeRef::ExprFormattedValue(node) => node.range(), AnyNodeRef::ExprFormattedValue(node) => node.range(),
AnyNodeRef::ExprJoinedStr(node) => node.range(), AnyNodeRef::ExprFString(node) => node.range(),
AnyNodeRef::ExprConstant(node) => node.range(), AnyNodeRef::ExprConstant(node) => node.range(),
AnyNodeRef::ExprAttribute(node) => node.range(), AnyNodeRef::ExprAttribute(node) => node.range(),
AnyNodeRef::ExprSubscript(node) => node.range(), AnyNodeRef::ExprSubscript(node) => node.range(),
@ -4981,7 +4981,7 @@ pub enum NodeKind {
ExprCompare, ExprCompare,
ExprCall, ExprCall,
ExprFormattedValue, ExprFormattedValue,
ExprJoinedStr, ExprFString,
ExprConstant, ExprConstant,
ExprAttribute, ExprAttribute,
ExprSubscript, ExprSubscript,

View file

@ -550,8 +550,8 @@ pub enum Expr {
Call(ExprCall), Call(ExprCall),
#[is(name = "formatted_value_expr")] #[is(name = "formatted_value_expr")]
FormattedValue(ExprFormattedValue), FormattedValue(ExprFormattedValue),
#[is(name = "joined_str_expr")] #[is(name = "f_string_expr")]
JoinedStr(ExprJoinedStr), FString(ExprFString),
#[is(name = "constant_expr")] #[is(name = "constant_expr")]
Constant(ExprConstant), Constant(ExprConstant),
#[is(name = "attribute_expr")] #[is(name = "attribute_expr")]
@ -878,14 +878,14 @@ pub struct DebugText {
/// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr) /// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct ExprJoinedStr { pub struct ExprFString {
pub range: TextRange, pub range: TextRange,
pub values: Vec<Expr>, pub values: Vec<Expr>,
} }
impl From<ExprJoinedStr> for Expr { impl From<ExprFString> for Expr {
fn from(payload: ExprJoinedStr) -> Self { fn from(payload: ExprFString) -> Self {
Expr::JoinedStr(payload) Expr::FString(payload)
} }
} }
@ -2814,7 +2814,7 @@ impl Ranged for crate::nodes::ExprFormattedValue {
self.range self.range
} }
} }
impl Ranged for crate::nodes::ExprJoinedStr { impl Ranged for crate::nodes::ExprFString {
fn range(&self) -> TextRange { fn range(&self) -> TextRange {
self.range self.range
} }
@ -2885,7 +2885,7 @@ impl Ranged for crate::Expr {
Self::Compare(node) => node.range(), Self::Compare(node) => node.range(),
Self::Call(node) => node.range(), Self::Call(node) => node.range(),
Self::FormattedValue(node) => node.range(), Self::FormattedValue(node) => node.range(),
Self::JoinedStr(node) => node.range(), Self::FString(node) => node.range(),
Self::Constant(node) => node.range(), Self::Constant(node) => node.range(),
Self::Attribute(node) => node.range(), Self::Attribute(node) => node.range(),
Self::Subscript(node) => node.range(), Self::Subscript(node) => node.range(),

View file

@ -140,7 +140,7 @@ pub fn relocate_expr(expr: &mut Expr, location: TextRange) {
relocate_expr(expr, location); relocate_expr(expr, location);
} }
} }
Expr::JoinedStr(nodes::ExprJoinedStr { values, range }) => { Expr::FString(nodes::ExprFString { values, range }) => {
*range = location; *range = location;
for expr in values { for expr in values {
relocate_expr(expr, location); relocate_expr(expr, location);

View file

@ -476,7 +476,7 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
visitor.visit_format_spec(expr); visitor.visit_format_spec(expr);
} }
} }
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
for expr in values { for expr in values {
visitor.visit_expr(expr); visitor.visit_expr(expr);
} }

View file

@ -570,7 +570,7 @@ where
} }
} }
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
for expr in values { for expr in values {
visitor.visit_expr(expr); visitor.visit_expr(expr);
} }

View file

@ -1104,8 +1104,8 @@ impl<'a> Generator<'a> {
*conversion, *conversion,
format_spec.as_deref(), format_spec.as_deref(),
), ),
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
self.unparse_joinedstr(values, false); self.unparse_f_string(values, false);
} }
Expr::Constant(ast::ExprConstant { Expr::Constant(ast::ExprConstant {
value, value,
@ -1289,9 +1289,9 @@ impl<'a> Generator<'a> {
} }
} }
fn unparse_fstring_body(&mut self, values: &[Expr], is_spec: bool) { fn unparse_f_string_body(&mut self, values: &[Expr], is_spec: bool) {
for value in values { for value in values {
self.unparse_fstring_elem(value, is_spec); self.unparse_f_string_elem(value, is_spec);
} }
} }
@ -1330,23 +1330,23 @@ impl<'a> Generator<'a> {
if let Some(spec) = spec { if let Some(spec) = spec {
self.p(":"); self.p(":");
self.unparse_fstring_elem(spec, true); self.unparse_f_string_elem(spec, true);
} }
self.p("}"); self.p("}");
} }
fn unparse_fstring_elem(&mut self, expr: &Expr, is_spec: bool) { fn unparse_f_string_elem(&mut self, expr: &Expr, is_spec: bool) {
match expr { match expr {
Expr::Constant(ast::ExprConstant { value, .. }) => { Expr::Constant(ast::ExprConstant { value, .. }) => {
if let Constant::Str(s) = value { if let Constant::Str(s) = value {
self.unparse_fstring_str(s); self.unparse_f_string_literal(s);
} else { } else {
unreachable!() unreachable!()
} }
} }
Expr::JoinedStr(ast::ExprJoinedStr { values, range: _ }) => { Expr::FString(ast::ExprFString { values, range: _ }) => {
self.unparse_joinedstr(values, is_spec); self.unparse_f_string(values, is_spec);
} }
Expr::FormattedValue(ast::ExprFormattedValue { Expr::FormattedValue(ast::ExprFormattedValue {
value, value,
@ -1364,14 +1364,14 @@ impl<'a> Generator<'a> {
} }
} }
fn unparse_fstring_str(&mut self, s: &str) { fn unparse_f_string_literal(&mut self, s: &str) {
let s = s.replace('{', "{{").replace('}', "}}"); let s = s.replace('{', "{{").replace('}', "}}");
self.p(&s); self.p(&s);
} }
fn unparse_joinedstr(&mut self, values: &[Expr], is_spec: bool) { fn unparse_f_string(&mut self, values: &[Expr], is_spec: bool) {
if is_spec { if is_spec {
self.unparse_fstring_body(values, is_spec); self.unparse_f_string_body(values, is_spec);
} else { } else {
self.p("f"); self.p("f");
let mut generator = Generator::new( let mut generator = Generator::new(
@ -1382,7 +1382,7 @@ impl<'a> Generator<'a> {
}, },
self.line_ending, self.line_ending,
); );
generator.unparse_fstring_body(values, is_spec); generator.unparse_f_string_body(values, is_spec);
let body = &generator.buffer; let body = &generator.buffer;
self.p_str_repr(body); self.p_str_repr(body);
} }

View file

@ -5,18 +5,18 @@ use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter}; use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult; use ruff_formatter::FormatResult;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprJoinedStr; use ruff_python_ast::ExprFString;
#[derive(Default)] #[derive(Default)]
pub struct FormatExprJoinedStr; pub struct FormatExprFString;
impl FormatNodeRule<ExprJoinedStr> for FormatExprJoinedStr { impl FormatNodeRule<ExprFString> for FormatExprFString {
fn fmt_fields(&self, item: &ExprJoinedStr, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &ExprFString, f: &mut PyFormatter) -> FormatResult<()> {
FormatString::new(&AnyString::JoinedStr(item)).fmt(f) FormatString::new(&AnyString::FString(item)).fmt(f)
} }
} }
impl NeedsParentheses for ExprJoinedStr { impl NeedsParentheses for ExprFString {
fn needs_parentheses( fn needs_parentheses(
&self, &self,
_parent: AnyNodeRef, _parent: AnyNodeRef,

View file

@ -27,10 +27,10 @@ pub(crate) mod expr_compare;
pub(crate) mod expr_constant; pub(crate) mod expr_constant;
pub(crate) mod expr_dict; pub(crate) mod expr_dict;
pub(crate) mod expr_dict_comp; pub(crate) mod expr_dict_comp;
pub(crate) mod expr_f_string;
pub(crate) mod expr_formatted_value; pub(crate) mod expr_formatted_value;
pub(crate) mod expr_generator_exp; pub(crate) mod expr_generator_exp;
pub(crate) mod expr_if_exp; pub(crate) mod expr_if_exp;
pub(crate) mod expr_joined_str;
pub(crate) mod expr_lambda; pub(crate) mod expr_lambda;
pub(crate) mod expr_line_magic; pub(crate) mod expr_line_magic;
pub(crate) mod expr_list; pub(crate) mod expr_list;
@ -93,7 +93,7 @@ impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
Expr::Compare(expr) => expr.format().with_options(Some(parentheses)).fmt(f), Expr::Compare(expr) => expr.format().with_options(Some(parentheses)).fmt(f),
Expr::Call(expr) => expr.format().fmt(f), Expr::Call(expr) => expr.format().fmt(f),
Expr::FormattedValue(expr) => expr.format().fmt(f), Expr::FormattedValue(expr) => expr.format().fmt(f),
Expr::JoinedStr(expr) => expr.format().fmt(f), Expr::FString(expr) => expr.format().fmt(f),
Expr::Constant(expr) => expr.format().fmt(f), Expr::Constant(expr) => expr.format().fmt(f),
Expr::Attribute(expr) => expr.format().fmt(f), Expr::Attribute(expr) => expr.format().fmt(f),
Expr::Subscript(expr) => expr.format().fmt(f), Expr::Subscript(expr) => expr.format().fmt(f),
@ -231,7 +231,7 @@ impl NeedsParentheses for Expr {
Expr::Compare(expr) => expr.needs_parentheses(parent, context), Expr::Compare(expr) => expr.needs_parentheses(parent, context),
Expr::Call(expr) => expr.needs_parentheses(parent, context), Expr::Call(expr) => expr.needs_parentheses(parent, context),
Expr::FormattedValue(expr) => expr.needs_parentheses(parent, context), Expr::FormattedValue(expr) => expr.needs_parentheses(parent, context),
Expr::JoinedStr(expr) => expr.needs_parentheses(parent, context), Expr::FString(expr) => expr.needs_parentheses(parent, context),
Expr::Constant(expr) => expr.needs_parentheses(parent, context), Expr::Constant(expr) => expr.needs_parentheses(parent, context),
Expr::Attribute(expr) => expr.needs_parentheses(parent, context), Expr::Attribute(expr) => expr.needs_parentheses(parent, context),
Expr::Subscript(expr) => expr.needs_parentheses(parent, context), Expr::Subscript(expr) => expr.needs_parentheses(parent, context),
@ -429,7 +429,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
| Expr::Yield(_) | Expr::Yield(_)
| Expr::YieldFrom(_) | Expr::YieldFrom(_)
| Expr::FormattedValue(_) | Expr::FormattedValue(_)
| Expr::JoinedStr(_) | Expr::FString(_)
| Expr::Constant(_) | Expr::Constant(_)
| Expr::Starred(_) | Expr::Starred(_)
| Expr::Name(_) | Expr::Name(_)

View file

@ -2,7 +2,7 @@ use std::borrow::Cow;
use bitflags::bitflags; use bitflags::bitflags;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{self as ast, ExprConstant, ExprJoinedStr, Ranged}; use ruff_python_ast::{self as ast, ExprConstant, ExprFString, Ranged};
use ruff_python_parser::lexer::{lex_starts_at, LexicalError, LexicalErrorType}; use ruff_python_parser::lexer::{lex_starts_at, LexicalError, LexicalErrorType};
use ruff_python_parser::{Mode, Tok}; use ruff_python_parser::{Mode, Tok};
use ruff_source_file::Locator; use ruff_source_file::Locator;
@ -27,15 +27,15 @@ enum Quoting {
pub(super) enum AnyString<'a> { pub(super) enum AnyString<'a> {
Constant(&'a ExprConstant), Constant(&'a ExprConstant),
JoinedStr(&'a ExprJoinedStr), FString(&'a ExprFString),
} }
impl<'a> AnyString<'a> { impl<'a> AnyString<'a> {
fn quoting(&self, locator: &Locator) -> Quoting { fn quoting(&self, locator: &Locator) -> Quoting {
match self { match self {
Self::Constant(_) => Quoting::CanChange, Self::Constant(_) => Quoting::CanChange,
Self::JoinedStr(joined_str) => { Self::FString(f_string) => {
if joined_str.values.iter().any(|value| match value { if f_string.values.iter().any(|value| match value {
Expr::FormattedValue(ast::ExprFormattedValue { range, .. }) => { Expr::FormattedValue(ast::ExprFormattedValue { range, .. }) => {
let string_content = locator.slice(*range); let string_content = locator.slice(*range);
string_content.contains(['"', '\'']) string_content.contains(['"', '\''])
@ -55,7 +55,7 @@ impl Ranged for AnyString<'_> {
fn range(&self) -> TextRange { fn range(&self) -> TextRange {
match self { match self {
Self::Constant(expr) => expr.range(), Self::Constant(expr) => expr.range(),
Self::JoinedStr(expr) => expr.range(), Self::FString(expr) => expr.range(),
} }
} }
} }
@ -64,7 +64,7 @@ impl<'a> From<&AnyString<'a>> for AnyNodeRef<'a> {
fn from(value: &AnyString<'a>) -> Self { fn from(value: &AnyString<'a>) -> Self {
match value { match value {
AnyString::Constant(expr) => AnyNodeRef::ExprConstant(expr), AnyString::Constant(expr) => AnyNodeRef::ExprConstant(expr),
AnyString::JoinedStr(expr) => AnyNodeRef::ExprJoinedStr(expr), AnyString::FString(expr) => AnyNodeRef::ExprFString(expr),
} }
} }
} }

View file

@ -1606,38 +1606,38 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprFormattedValue {
} }
} }
impl FormatRule<ast::ExprJoinedStr, PyFormatContext<'_>> impl FormatRule<ast::ExprFString, PyFormatContext<'_>>
for crate::expression::expr_joined_str::FormatExprJoinedStr for crate::expression::expr_f_string::FormatExprFString
{ {
#[inline] #[inline]
fn fmt(&self, node: &ast::ExprJoinedStr, f: &mut PyFormatter) -> FormatResult<()> { fn fmt(&self, node: &ast::ExprFString, f: &mut PyFormatter) -> FormatResult<()> {
FormatNodeRule::<ast::ExprJoinedStr>::fmt(self, node, f) FormatNodeRule::<ast::ExprFString>::fmt(self, node, f)
} }
} }
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprJoinedStr { impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::ExprFString {
type Format<'a> = FormatRefWithRule< type Format<'a> = FormatRefWithRule<
'a, 'a,
ast::ExprJoinedStr, ast::ExprFString,
crate::expression::expr_joined_str::FormatExprJoinedStr, crate::expression::expr_f_string::FormatExprFString,
PyFormatContext<'ast>, PyFormatContext<'ast>,
>; >;
fn format(&self) -> Self::Format<'_> { fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new( FormatRefWithRule::new(
self, self,
crate::expression::expr_joined_str::FormatExprJoinedStr::default(), crate::expression::expr_f_string::FormatExprFString::default(),
) )
} }
} }
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprJoinedStr { impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::ExprFString {
type Format = FormatOwnedWithRule< type Format = FormatOwnedWithRule<
ast::ExprJoinedStr, ast::ExprFString,
crate::expression::expr_joined_str::FormatExprJoinedStr, crate::expression::expr_f_string::FormatExprFString,
PyFormatContext<'ast>, PyFormatContext<'ast>,
>; >;
fn into_format(self) -> Self::Format { fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new( FormatOwnedWithRule::new(
self, self,
crate::expression::expr_joined_str::FormatExprJoinedStr::default(), crate::expression::expr_f_string::FormatExprFString::default(),
) )
} }
} }

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..14, range: 0..14,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..14, range: 0..14,
values: [ values: [
Constant( Constant(

View file

@ -79,8 +79,8 @@ expression: parse_ast
arguments: Arguments { arguments: Arguments {
range: 61..82, range: 61..82,
args: [ args: [
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 62..81, range: 62..81,
values: [ values: [
Constant( Constant(
@ -173,8 +173,8 @@ expression: parse_ast
arguments: Arguments { arguments: Arguments {
range: 113..134, range: 113..134,
args: [ args: [
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 114..133, range: 114..133,
values: [ values: [
Constant( Constant(

View file

@ -195,8 +195,8 @@ expression: parse_ast
arguments: Arguments { arguments: Arguments {
range: 132..180, range: 132..180,
args: [ args: [
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 133..179, range: 133..179,
values: [ values: [
Constant( Constant(
@ -323,8 +323,8 @@ expression: parse_ast
arguments: Arguments { arguments: Arguments {
range: 212..260, range: 212..260,
args: [ args: [
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 213..259, range: 213..259,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..22, range: 0..22,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..22, range: 0..22,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..8, range: 0..8,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..8, range: 0..8,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..8, range: 0..8,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..8, range: 0..8,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..9, range: 0..9,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..9, range: 0..9,
values: [ values: [
Constant( Constant(

View file

@ -21,8 +21,8 @@ expression: parse_ast
), ),
conversion: None, conversion: None,
format_spec: Some( format_spec: Some(
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 9..12, range: 9..12,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..11, range: 0..11,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..11, range: 0..11,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..17, range: 0..17,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..17, range: 0..17,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..17, range: 0..17,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..17, range: 0..17,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..22, range: 0..22,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..22, range: 0..22,
values: [ values: [
Constant( Constant(

View file

@ -16,8 +16,8 @@ expression: parse_ast
debug_text: None, debug_text: None,
conversion: None, conversion: None,
format_spec: Some( format_spec: Some(
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 7..13, range: 7..13,
values: [ values: [
FormattedValue( FormattedValue(

View file

@ -16,8 +16,8 @@ expression: parse_ast
debug_text: None, debug_text: None,
conversion: None, conversion: None,
format_spec: Some( format_spec: Some(
JoinedStr( FString(
ExprJoinedStr { ExprFString {
range: 7..11, range: 7..11,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..18, range: 0..18,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..18, range: 0..18,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..22, range: 0..22,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..22, range: 0..22,
values: [ values: [
Constant( Constant(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..7, range: 0..7,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..7, range: 0..7,
values: [ values: [
FormattedValue( FormattedValue(

View file

@ -6,8 +6,8 @@ expression: parse_ast
Expr( Expr(
StmtExpr { StmtExpr {
range: 0..11, range: 0..11,
value: JoinedStr( value: FString(
ExprJoinedStr { ExprFString {
range: 0..11, range: 0..11,
values: [ values: [
FormattedValue( FormattedValue(

View file

@ -243,7 +243,7 @@ impl<'a> StringParser<'a> {
let start_location = self.get_pos(); let start_location = self.get_pos();
let parsed_spec = self.parse_spec(nested)?; let parsed_spec = self.parse_spec(nested)?;
spec = Some(Box::new(Expr::from(ast::ExprJoinedStr { spec = Some(Box::new(Expr::from(ast::ExprFString {
values: parsed_spec, values: parsed_spec,
range: self.range(start_location), range: self.range(start_location),
}))); })));
@ -671,7 +671,7 @@ pub(crate) fn parse_strings(
deduped.push(take_current(&mut current, current_start, current_end)); deduped.push(take_current(&mut current, current_start, current_end));
} }
Ok(Expr::JoinedStr(ast::ExprJoinedStr { Ok(Expr::FString(ast::ExprFString {
values: deduped, values: deduped,
range: TextRange::new(initial_start, last_end), range: TextRange::new(initial_start, last_end),
})) }))

View file

@ -54,7 +54,7 @@ impl From<&Expr> for PythonType {
Expr::ListComp(_) => PythonType::List, Expr::ListComp(_) => PythonType::List,
Expr::Tuple(_) => PythonType::Tuple, Expr::Tuple(_) => PythonType::Tuple,
Expr::GeneratorExp(_) => PythonType::Generator, Expr::GeneratorExp(_) => PythonType::Generator,
Expr::JoinedStr(_) => PythonType::String, Expr::FString(_) => PythonType::String,
Expr::BinOp(ast::ExprBinOp { left, op, .. }) => { Expr::BinOp(ast::ExprBinOp { left, op, .. }) => {
// Ex) "a" % "b" // Ex) "a" % "b"
if op.is_mod() { if op.is_mod() {