mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Specialize ConversionFlag (#4450)
This commit is contained in:
parent
f0465bf106
commit
4b05ca1198
8 changed files with 36 additions and 27 deletions
|
@ -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<ComparableExpr<'a>>,
|
||||
conversion: Int,
|
||||
conversion: ConversionFlag,
|
||||
format_spec: Option<Box<ComparableExpr<'a>>>,
|
||||
},
|
||||
JoinedStr {
|
||||
|
|
|
@ -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<U>(&mut self, val: &Expr<U>, conversion: Int, spec: Option<&Expr<U>>) {
|
||||
fn unparse_formatted<U>(
|
||||
&mut self,
|
||||
val: &Expr<U>,
|
||||
conversion: ConversionFlag,
|
||||
spec: Option<&Expr<U>>,
|
||||
) {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue