diff --git a/Cargo.lock b/Cargo.lock index 2bbd5602a3..36e2f02498 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2001,7 +2001,7 @@ dependencies = [ [[package]] name = "ruff_text_size" version = "0.0.0" -source = "git+https://github.com/RustPython/Parser.git?rev=735c06d5f43da05d191f32442224f082f1d202ee#735c06d5f43da05d191f32442224f082f1d202ee" +source = "git+https://github.com/RustPython/Parser.git?rev=e820928f11a2453314ad4d5ce23f066d1d3faf73#e820928f11a2453314ad4d5ce23f066d1d3faf73" dependencies = [ "schemars", "serde", @@ -2072,7 +2072,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=735c06d5f43da05d191f32442224f082f1d202ee#735c06d5f43da05d191f32442224f082f1d202ee" +source = "git+https://github.com/RustPython/Parser.git?rev=e820928f11a2453314ad4d5ce23f066d1d3faf73#e820928f11a2453314ad4d5ce23f066d1d3faf73" dependencies = [ "is-macro", "num-bigint", @@ -2083,7 +2083,7 @@ dependencies = [ [[package]] name = "rustpython-format" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=735c06d5f43da05d191f32442224f082f1d202ee#735c06d5f43da05d191f32442224f082f1d202ee" +source = "git+https://github.com/RustPython/Parser.git?rev=e820928f11a2453314ad4d5ce23f066d1d3faf73#e820928f11a2453314ad4d5ce23f066d1d3faf73" dependencies = [ "bitflags 2.2.1", "itertools", @@ -2095,9 +2095,10 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=735c06d5f43da05d191f32442224f082f1d202ee#735c06d5f43da05d191f32442224f082f1d202ee" +source = "git+https://github.com/RustPython/Parser.git?rev=e820928f11a2453314ad4d5ce23f066d1d3faf73#e820928f11a2453314ad4d5ce23f066d1d3faf73" dependencies = [ "hexf-parse", + "is-macro", "lexical-parse-float", "num-traits", "unic-ucd-category", @@ -2106,9 +2107,10 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=735c06d5f43da05d191f32442224f082f1d202ee#735c06d5f43da05d191f32442224f082f1d202ee" +source = "git+https://github.com/RustPython/Parser.git?rev=e820928f11a2453314ad4d5ce23f066d1d3faf73#e820928f11a2453314ad4d5ce23f066d1d3faf73" dependencies = [ "anyhow", + "is-macro", "itertools", "lalrpop-util", "log", @@ -2128,8 +2130,9 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.2.0" -source = "git+https://github.com/RustPython/Parser.git?rev=735c06d5f43da05d191f32442224f082f1d202ee#735c06d5f43da05d191f32442224f082f1d202ee" +source = "git+https://github.com/RustPython/Parser.git?rev=e820928f11a2453314ad4d5ce23f066d1d3faf73#e820928f11a2453314ad4d5ce23f066d1d3faf73" dependencies = [ + "is-macro", "ruff_text_size", ] diff --git a/Cargo.toml b/Cargo.toml index 3d9046ff4b..25f2da974a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,10 +31,10 @@ proc-macro2 = { version = "1.0.51" } quote = { version = "1.0.23" } regex = { version = "1.7.1" } rustc-hash = { version = "1.1.0" } -ruff_text_size = { git = "https://github.com/RustPython/Parser.git", rev = "735c06d5f43da05d191f32442224f082f1d202ee" } -rustpython-format = { git = "https://github.com/RustPython/Parser.git", rev = "735c06d5f43da05d191f32442224f082f1d202ee" } -rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "735c06d5f43da05d191f32442224f082f1d202ee" } -rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "735c06d5f43da05d191f32442224f082f1d202ee", default-features = false, features = ["full-lexer", "all-nodes-with-ranges"] } +ruff_text_size = { git = "https://github.com/RustPython/Parser.git", rev = "e820928f11a2453314ad4d5ce23f066d1d3faf73" } +rustpython-format = { git = "https://github.com/RustPython/Parser.git", rev = "e820928f11a2453314ad4d5ce23f066d1d3faf73" } +rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "e820928f11a2453314ad4d5ce23f066d1d3faf73" } +rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "e820928f11a2453314ad4d5ce23f066d1d3faf73", default-features = false, features = ["full-lexer", "all-nodes-with-ranges"] } schemars = { version = "0.8.12" } serde = { version = "1.0.152", features = ["derive"] } serde_json = { version = "1.0.93", features = ["preserve_order"] } diff --git a/crates/ruff/src/rules/flynt/helpers.rs b/crates/ruff/src/rules/flynt/helpers.rs index c2e7f324df..2530740a63 100644 --- a/crates/ruff/src/rules/flynt/helpers.rs +++ b/crates/ruff/src/rules/flynt/helpers.rs @@ -1,11 +1,11 @@ use ruff_text_size::TextRange; -use rustpython_parser::ast::{self, Constant, Expr, Int}; +use rustpython_parser::ast::{self, Constant, ConversionFlag, Expr}; /// Wrap an expression in a `FormattedValue` with no special formatting. fn to_formatted_value_expr(inner: &Expr) -> Expr { let node = ast::ExprFormattedValue { value: Box::new(inner.clone()), - conversion: Int::new(0), + conversion: ConversionFlag::None, format_spec: None, range: TextRange::default(), }; diff --git a/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index ef5798ba6d..219176d49e 100644 --- a/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -1,4 +1,4 @@ -use rustpython_parser::ast::{self, Expr, Ranged}; +use rustpython_parser::ast::{self, ConversionFlag, Expr, Ranged}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; @@ -43,10 +43,10 @@ impl AlwaysAutofixableViolation for ExplicitFStringTypeConversion { pub(crate) fn explicit_f_string_type_conversion( checker: &mut Checker, formatted_value: &Expr, - conversion: ast::Int, + conversion: ConversionFlag, ) { // Skip if there's already a conversion flag. - if conversion != ast::ConversionFlag::None as u32 { + if !conversion.is_none() { return; } diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index b6cff49c97..fda1c0f8ee 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -3,8 +3,9 @@ use num_bigint::BigInt; use rustpython_parser::ast::{ - self, Alias, Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, Excepthandler, Expr, - ExprContext, Identifier, Int, Keyword, MatchCase, Operator, Pattern, Stmt, Unaryop, Withitem, + self, Alias, Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, ConversionFlag, + Excepthandler, Expr, ExprContext, Identifier, Int, Keyword, MatchCase, Operator, Pattern, Stmt, + Unaryop, Withitem, }; #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)] @@ -481,7 +482,7 @@ pub enum ComparableExpr<'a> { }, FormattedValue { value: Box>, - conversion: Int, + conversion: ConversionFlag, format_spec: Option>>, }, JoinedStr { diff --git a/crates/ruff_python_ast/src/source_code/generator.rs b/crates/ruff_python_ast/src/source_code/generator.rs index 83cc4a1ce9..0f7573a501 100644 --- a/crates/ruff_python_ast/src/source_code/generator.rs +++ b/crates/ruff_python_ast/src/source_code/generator.rs @@ -5,7 +5,7 @@ use std::ops::Deref; use rustpython_literal::escape::{AsciiEscape, Escape, UnicodeEscape}; use rustpython_parser::ast::{ self, Alias, Arg, Arguments, Boolop, Cmpop, Comprehension, Constant, ConversionFlag, - Excepthandler, Expr, Identifier, Int, MatchCase, Operator, Pattern, Stmt, Suite, Withitem, + Excepthandler, Expr, Identifier, MatchCase, Operator, Pattern, Stmt, Suite, Withitem, }; use crate::newlines::LineEnding; @@ -1340,7 +1340,12 @@ impl<'a> Generator<'a> { } } - fn unparse_formatted(&mut self, val: &Expr, conversion: Int, spec: Option<&Expr>) { + fn unparse_formatted( + &mut self, + val: &Expr, + conversion: ConversionFlag, + spec: Option<&Expr>, + ) { let mut generator = Generator::new(self.indent, self.quote, self.line_ending); generator.unparse_expr(val, precedence::FORMATTED_VALUE); let brace = if generator.buffer.starts_with('{') { @@ -1352,10 +1357,10 @@ impl<'a> Generator<'a> { self.p(brace); self.buffer += &generator.buffer; - if conversion.to_u32() != ConversionFlag::None as u32 { + if !conversion.is_none() { self.p("!"); #[allow(clippy::cast_possible_truncation)] - self.p(&format!("{}", conversion.to_u32() as u8 as char)); + self.p(&format!("{}", conversion as u8 as char)); } if let Some(spec) = spec { diff --git a/crates/ruff_python_formatter/src/cst/mod.rs b/crates/ruff_python_formatter/src/cst/mod.rs index f40292c14d..e0222d3efe 100644 --- a/crates/ruff_python_formatter/src/cst/mod.rs +++ b/crates/ruff_python_formatter/src/cst/mod.rs @@ -5,7 +5,7 @@ use std::ops::Deref; use itertools::Itertools; use ruff_text_size::{TextRange, TextSize}; -use rustpython_parser::ast::{Constant, Ranged}; +use rustpython_parser::ast::{Constant, ConversionFlag, Ranged}; use rustpython_parser::{ast, Mode}; use ruff_python_ast::source_code::Locator; @@ -410,7 +410,7 @@ pub enum ExprKind { }, FormattedValue { value: Box, - conversion: usize, + conversion: ConversionFlag, format_spec: Option>, }, JoinedStr { @@ -2038,7 +2038,7 @@ impl From<(rustpython_parser::ast::Expr, &Locator<'_>)> for Expr { range, node: ExprKind::FormattedValue { value: Box::new((*value, locator).into()), - conversion: conversion.to_usize(), + conversion, format_spec: format_spec.map(|f| Box::new((*f, locator).into())), }, trivia: vec![], diff --git a/crates/ruff_python_formatter/src/format/expr.rs b/crates/ruff_python_formatter/src/format/expr.rs index 51bfbc469c..5aa139b7bd 100644 --- a/crates/ruff_python_formatter/src/format/expr.rs +++ b/crates/ruff_python_formatter/src/format/expr.rs @@ -1,6 +1,6 @@ #![allow(unused_variables, clippy::too_many_arguments)] -use rustpython_parser::ast::Constant; +use rustpython_parser::ast::{Constant, ConversionFlag}; use ruff_formatter::prelude::*; use ruff_formatter::{format_args, write}; @@ -246,7 +246,7 @@ fn format_formatted_value( f: &mut Formatter, expr: &Expr, value: &Expr, - _conversion: usize, + _conversion: ConversionFlag, format_spec: Option<&Expr>, ) -> FormatResult<()> { write!(f, [text("!")])?;