Merge pull request #7001 from youknowone/annotationlib

Add test_annotationlib to v3.14.2 and fix related bugs
This commit is contained in:
Jeong, YunWon authored and GitHub committed 2026-02-05 23:39:47 +09:00
commit 18ac6dd63b
3 files changed
+2241 -4

No files matched your search

+2215
View File
File diff suppressed because it is too large. Load diff
+13 -3
View File
@@ -22,7 +22,7 @@ use malachite_bigint::BigInt;
use num_complex::Complex;
use num_traits::{Num, ToPrimitive};
use ruff_python_ast as ast;
use ruff_text_size::{Ranged, TextRange};
use ruff_text_size::{Ranged, TextRange, TextSize};
use std::collections::HashSet;
use rustpython_compiler_core::{
@@ -8382,9 +8382,19 @@ impl Compiler {
// Compile the interpolation value
self.compile_expression(&interp.expression)?;
// Load the expression source string
// Load the expression source string, including any
// whitespace between '{' and the expression start
let expr_range = interp.expression.range();
let expr_source = self.source_file.slice(expr_range);
let expr_source = if interp.range.start() < expr_range.start()
&& interp.range.end() >= expr_range.end()
{
let after_brace = interp.range.start() + TextSize::new(1);
self.source_file
.slice(TextRange::new(after_brace, expr_range.end()))
} else {
// Fallback for programmatically constructed ASTs with dummy ranges
self.source_file.slice(expr_range)
};
self.emit_load_const(ConstantData::Str {
value: expr_source.to_string().into(),
});
+13 -1
View File
@@ -561,7 +561,19 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
// put a space to avoid escaping the bracket
"{ "
} else {
"{"
// Preserve leading whitespace between '{' and the expression
let source_text = self.source.source_text();
let start = val.range().start().to_usize();
if start > 0
&& source_text
.as_bytes()
.get(start - 1)
.is_some_and(|b| b.is_ascii_whitespace())
{
"{ "
} else {
"{"
}
};
self.p(brace)?;
self.p(&buffered)?;