mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update Ruff to 0.16.5 (#8617)
Pin the RustPython Ruff fork to the patch commit based on Ruff 0.16.5 and adapt compiler and AST integration to the updated APIs. Assisted-by: Codex:GPT-5
This commit is contained in:
1 parent
531cf2b378
commit
96925f49f8
20 files changed
+217
-91
No files matched your search
@@ -24,7 +24,7 @@ use malachite_bigint::BigInt;
|
||||
use num_complex::Complex;
|
||||
use num_traits::{Num, ToPrimitive, Zero};
|
||||
use ruff_python_ast::{self as ast, name::Name};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize, TextSlice};
|
||||
use rustpython_compiler_core::{
|
||||
Mode, OneIndexed, PositionEncoding, SourceFile, SourceLocation,
|
||||
bytecode::{
|
||||
@@ -9129,7 +9129,12 @@ impl<'warnings> Compiler<'warnings> {
|
||||
range,
|
||||
..
|
||||
}) => {
|
||||
let key = key.as_ref();
|
||||
let Some(key) = key.as_deref() else {
|
||||
self.set_source_range(*range);
|
||||
return Err(self.error(CodegenErrorType::SyntaxError(
|
||||
"dict unpacking cannot be used in dict comprehension".to_owned(),
|
||||
)));
|
||||
};
|
||||
self.compile_comprehension(
|
||||
"<dictcomp>",
|
||||
Some(
|
||||
@@ -9644,7 +9649,11 @@ impl<'warnings> Compiler<'warnings> {
|
||||
continue;
|
||||
};
|
||||
for other in &keywords[i + 1..] {
|
||||
if other.arg.as_ref() == Some(arg) {
|
||||
if other
|
||||
.arg
|
||||
.as_ref()
|
||||
.is_some_and(|other| other.as_str() == arg.as_str())
|
||||
{
|
||||
return Err(self.error_ranged(
|
||||
CodegenErrorType::SyntaxError(format!("keyword argument repeated: {arg}")),
|
||||
other.range,
|
||||
@@ -10067,7 +10076,11 @@ impl<'warnings> Compiler<'warnings> {
|
||||
self.visit_expr(&first.iter);
|
||||
}
|
||||
if self.consume_inlined_comprehension_scope() {
|
||||
self.visit_comprehension_tail(key, Some(value), generators);
|
||||
if let Some(key) = key.as_deref() {
|
||||
self.visit_comprehension_tail(key, Some(value), generators);
|
||||
} else {
|
||||
self.visit_comprehension_tail(value, None, generators);
|
||||
}
|
||||
} else {
|
||||
self.consume_scope();
|
||||
}
|
||||
@@ -13249,9 +13262,10 @@ impl<'warnings> Compiler<'warnings> {
|
||||
{
|
||||
let after_brace = interp.range.start() + TextSize::new(1);
|
||||
self.source_file
|
||||
.source_text()
|
||||
.slice(TextRange::new(after_brace, expr_range.end()))
|
||||
} else {
|
||||
self.source_file.slice(expr_range)
|
||||
self.source_file.source_text().slice(expr_range)
|
||||
}
|
||||
.to_string();
|
||||
self.set_source_range(interp.range);
|
||||
@@ -13843,7 +13857,7 @@ mod tests {
|
||||
fn frozenset_call_expr() -> ast::Expr {
|
||||
ast::Expr::Call(ast::ExprCall {
|
||||
node_index: ast::AtomicNodeIndex::NONE,
|
||||
range: TextRange::default(),
|
||||
range_start: TextSize::default(),
|
||||
func: Box::new(ast::Expr::Name(ast::ExprName {
|
||||
node_index: ast::AtomicNodeIndex::NONE,
|
||||
range: TextRange::default(),
|
||||
@@ -13996,7 +14010,7 @@ mod tests {
|
||||
);
|
||||
let message = first_ast_constant_warning(ast::Expr::Call(ast::ExprCall {
|
||||
node_index: ast::AtomicNodeIndex::NONE,
|
||||
range: TextRange::default(),
|
||||
range_start: TextSize::default(),
|
||||
func: Box::new(func),
|
||||
arguments: ast::Arguments {
|
||||
node_index: ast::AtomicNodeIndex::NONE,
|
||||
|
||||
@@ -24,7 +24,7 @@ mod unparse;
|
||||
|
||||
pub use compile::CompileOpts;
|
||||
use ruff_python_ast as ast;
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize, TextSlice};
|
||||
use rustpython_compiler_core::SourceFile;
|
||||
use rustpython_wtf8::Wtf8Buf;
|
||||
|
||||
@@ -116,7 +116,7 @@ pub fn decorated_definition_range(
|
||||
return statement_range;
|
||||
}
|
||||
let search_range = TextRange::new(search_start, statement_range.end());
|
||||
let source = source_file.slice(search_range);
|
||||
let source = source_file.source_text().slice(search_range);
|
||||
let Some(keyword_offset) = source.find(keyword) else {
|
||||
return statement_range;
|
||||
};
|
||||
@@ -151,7 +151,7 @@ pub fn string_literal_value(source_file: &SourceFile, string: &ast::StringLitera
|
||||
#[must_use]
|
||||
pub fn string_literal_part_value(source_file: &SourceFile, string: &ast::StringLiteral) -> Wtf8Buf {
|
||||
if string.value.contains(char::REPLACEMENT_CHARACTER) {
|
||||
let source = source_file.slice(string.range);
|
||||
let source = source_file.source_text().slice(string.range);
|
||||
string_parser::parse_string_literal(source, string.flags.into()).into()
|
||||
} else {
|
||||
string.value.to_string().into()
|
||||
@@ -167,7 +167,7 @@ pub fn interpolated_string_literal_value(
|
||||
flags: ast::AnyStringFlags,
|
||||
) -> Wtf8Buf {
|
||||
if element.value.contains(char::REPLACEMENT_CHARACTER) {
|
||||
let source = source_file.slice(element.range);
|
||||
let source = source_file.source_text().slice(element.range);
|
||||
string_parser::parse_fstring_literal_element(source.into(), flags).into()
|
||||
} else {
|
||||
element.value.to_string().into()
|
||||
@@ -186,11 +186,11 @@ pub fn interpolation_debug_text(
|
||||
debug_text: &ast::DebugText,
|
||||
expression_range: TextRange,
|
||||
) -> (String, TextRange) {
|
||||
let leading = debug_text.leading.as_str();
|
||||
let trailing = debug_text.trailing.as_str();
|
||||
let leading = debug_text.leading();
|
||||
let trailing = debug_text.trailing();
|
||||
let text = [
|
||||
strip_python_comments(leading).as_str(),
|
||||
source_file.slice(expression_range),
|
||||
source_file.source_text().slice(expression_range),
|
||||
strip_python_comments(trailing).as_str(),
|
||||
]
|
||||
.concat();
|
||||
|
||||
@@ -2376,7 +2376,12 @@ impl SymbolTableBuilder {
|
||||
self.in_iter_def_exp = true;
|
||||
}
|
||||
// Dict comprehension - is_generator = false (can be inlined)
|
||||
let key = key.as_ref();
|
||||
let Some(key) = key.as_deref() else {
|
||||
return Err(self.error_ranged(
|
||||
"dict unpacking cannot be used in dict comprehension".to_owned(),
|
||||
*range,
|
||||
));
|
||||
};
|
||||
self.scan_comprehension(
|
||||
&"<dictcomp>".into(),
|
||||
key,
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::strip_python_comments;
|
||||
use alloc::fmt;
|
||||
use core::fmt::Display as _;
|
||||
use ruff_python_ast as ast;
|
||||
use ruff_text_size::{Ranged, TextSize};
|
||||
use ruff_text_size::{Ranged, TextSize, TextSlice};
|
||||
use rustpython_compiler_core::SourceFile;
|
||||
use rustpython_literal::escape::{AsciiEscape, UnicodeEscape};
|
||||
|
||||
@@ -322,8 +322,12 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
|
||||
..
|
||||
}) => {
|
||||
self.p("{")?;
|
||||
self.unparse_expr(key, precedence::TEST)?;
|
||||
self.p(": ")?;
|
||||
if let Some(key) = key {
|
||||
self.unparse_expr(key, precedence::TEST)?;
|
||||
self.p(": ")?;
|
||||
} else {
|
||||
self.p("**")?;
|
||||
}
|
||||
self.unparse_expr(value, precedence::TEST)?;
|
||||
self.unparse_comp(generators)?;
|
||||
self.p("}")?;
|
||||
@@ -399,7 +403,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
|
||||
func,
|
||||
arguments: ast::Arguments { args, keywords, .. },
|
||||
node_index: _,
|
||||
range: _range,
|
||||
range_start: _range_start,
|
||||
..
|
||||
}) => {
|
||||
self.unparse_expr(func, precedence::ATOM)?;
|
||||
@@ -618,10 +622,10 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
|
||||
fmt::from_fn(|f| Unparser::new(f, self.source).unparse_expr(val, precedence::TEST + 1))
|
||||
.to_string();
|
||||
if let Some(debug_text) = debug_text {
|
||||
let leading = debug_text.leading.as_str();
|
||||
let trailing = debug_text.trailing.as_str();
|
||||
let leading = debug_text.leading();
|
||||
let trailing = debug_text.trailing();
|
||||
self.p(leading)?;
|
||||
self.p(self.source.slice(val.range()))?;
|
||||
self.p(self.source.source_text().slice(val.range()))?;
|
||||
self.p(trailing)?;
|
||||
if conversion == ast::ConversionFlag::None && spec.is_none() {
|
||||
conversion = ast::ConversionFlag::Repr;
|
||||
@@ -744,9 +748,13 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
|
||||
let mut conversion = source_conversion;
|
||||
let debug_parts = interpolation.debug_text.as_ref().map(|debug_text| {
|
||||
(
|
||||
strip_python_comments(debug_text.leading.as_str()),
|
||||
strip_python_comments(self.source.slice(interpolation.expression.range())),
|
||||
strip_python_comments(debug_text.trailing.as_str()),
|
||||
strip_python_comments(debug_text.leading()),
|
||||
strip_python_comments(
|
||||
self.source
|
||||
.source_text()
|
||||
.slice(interpolation.expression.range()),
|
||||
),
|
||||
strip_python_comments(debug_text.trailing()),
|
||||
)
|
||||
});
|
||||
if let Some((leading, source, trailing)) = &debug_parts {
|
||||
@@ -784,6 +792,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
|
||||
{
|
||||
strip_python_comments(
|
||||
self.source
|
||||
.source_text()
|
||||
.slice(ruff_text_size::TextRange::new(after_brace, expression_end)),
|
||||
)
|
||||
.trim_end()
|
||||
|
||||
Reference in new issue
Block a user