@@ -22,7 +22,7 @@ use malachite_bigint::BigInt;
2222use num_complex:: Complex ;
2323use num_traits:: { Num , ToPrimitive } ;
2424use ruff_python_ast as ast;
25- use ruff_text_size:: { Ranged , TextRange } ;
25+ use ruff_text_size:: { Ranged , TextRange , TextSize } ;
2626use std:: collections:: HashSet ;
2727
2828use rustpython_compiler_core:: {
@@ -8366,9 +8366,19 @@ impl Compiler {
83668366 // Compile the interpolation value
83678367 self . compile_expression ( & interp. expression ) ?;
83688368
8369- // Load the expression source string
8369+ // Load the expression source string, including any
8370+ // whitespace between '{' and the expression start
83708371 let expr_range = interp. expression . range ( ) ;
8371- let expr_source = self . source_file . slice ( expr_range) ;
8372+ let expr_source = if interp. range . start ( ) < expr_range. start ( )
8373+ && interp. range . end ( ) >= expr_range. end ( )
8374+ {
8375+ let after_brace = interp. range . start ( ) + TextSize :: new ( 1 ) ;
8376+ self . source_file
8377+ . slice ( TextRange :: new ( after_brace, expr_range. end ( ) ) )
8378+ } else {
8379+ // Fallback for programmatically constructed ASTs with dummy ranges
8380+ self . source_file . slice ( expr_range)
8381+ } ;
83728382 self . emit_load_const ( ConstantData :: Str {
83738383 value : expr_source. to_string ( ) . into ( ) ,
83748384 } ) ;
0 commit comments