Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix more
  • Loading branch information
youknowone committed Feb 5, 2026
commit bb9b56a31d34ddf96c990f543225d98b4dbe8065
25 changes: 17 additions & 8 deletions crates/vm/src/stdlib/ast/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn ruff_format_spec_to_joined_str(
let values: Vec<_> = ruff_fstring_element_into_iter(elements)
.map(ruff_fstring_element_to_joined_str_part)
.collect();
let values = values.into_boxed_slice();
let values = normalize_joined_str_parts(values).into_boxed_slice();
Some(Box::new(JoinedStr { range, values }))
}
}
Expand Down Expand Up @@ -610,10 +610,19 @@ fn tstring_interpolation_expr_str(
interpolation_range: TextRange,
expr_range: TextRange,
) -> String {
let expr_range =
extend_expr_range_with_wrapping_parens(source_file, interpolation_range, expr_range)
.unwrap_or(expr_range);
let expr_source = source_file.slice(expr_range);
let expr_range = extend_expr_range_with_wrapping_parens(
source_file,
interpolation_range,
expr_range,
)
.unwrap_or(expr_range);
let start = interpolation_range.start() + TextSize::from(1);
let start = if start > expr_range.end() {
expr_range.start()
} else {
start
};
let expr_source = source_file.slice(TextRange::new(start, expr_range.end()));
strip_interpolation_expr(expr_source)
}

Expand Down Expand Up @@ -667,10 +676,10 @@ fn strip_interpolation_expr(expr_source: &str) -> String {
for (idx, ch) in expr_source.char_indices().rev() {
if ch.is_whitespace() || ch == '=' {
end = idx;
} else {
end = idx + ch.len_utf8();
break;
continue;
}
end = idx + ch.len_utf8();
break;
}
expr_source[..end].to_owned()
}
Expand Down
8 changes: 8 additions & 0 deletions crates/vm/src/stdlib/ast/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ fn validate_expr(vm: &VirtualMachine, expr: &ast::Expr, ctx: ast::ExprContext) -
validate_expr(vm, &await_expr.value, ast::ExprContext::Load)
}
ast::Expr::Compare(compare) => {
if compare.comparators.is_empty() {
return Err(vm.new_value_error("Compare with no comparators".to_owned()));
}
if compare.comparators.len() != compare.ops.len() {
return Err(vm.new_value_error(
"Compare has a different number of comparators and operands".to_owned(),
));
}
validate_exprs(vm, &compare.comparators, ast::ExprContext::Load, false)?;
validate_expr(vm, &compare.left, ast::ExprContext::Load)
}
Expand Down