mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 05:51:03 -05:00
Remove some usages of default format for expressions (#2100)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
//! Generate Python source code from an abstract syntax tree (AST).
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
use std::ops::Deref;
|
||||
|
||||
use rustpython_ast::{Excepthandler, ExcepthandlerKind, Suite, Withitem};
|
||||
@@ -116,10 +115,6 @@ impl<'a> Generator<'a> {
|
||||
self.p_if(!std::mem::take(first), s);
|
||||
}
|
||||
|
||||
fn write_fmt(&mut self, f: fmt::Arguments<'_>) {
|
||||
self.buffer.write_fmt(f).unwrap();
|
||||
}
|
||||
|
||||
pub fn unparse_suite<U>(&mut self, suite: &Suite<U>) {
|
||||
for stmt in suite {
|
||||
self.unparse_stmt(stmt);
|
||||
@@ -928,7 +923,8 @@ impl<'a> Generator<'a> {
|
||||
self.p_delim(&mut first, ", ");
|
||||
self.unparse_arg(arg);
|
||||
if let Some(i) = i.checked_sub(defaults_start) {
|
||||
write!(self, "={}", &args.defaults[i]);
|
||||
self.p("=");
|
||||
self.unparse_expr(&args.defaults[i], precedence::TEST);
|
||||
}
|
||||
self.p_if(i + 1 == args.posonlyargs.len(), ", /");
|
||||
}
|
||||
@@ -947,7 +943,8 @@ impl<'a> Generator<'a> {
|
||||
.checked_sub(defaults_start)
|
||||
.and_then(|i| args.kw_defaults.get(i))
|
||||
{
|
||||
write!(self, "={default}");
|
||||
self.p("=");
|
||||
self.unparse_expr(default, precedence::TEST);
|
||||
}
|
||||
}
|
||||
if let Some(kwarg) = &args.kwarg {
|
||||
@@ -960,7 +957,8 @@ impl<'a> Generator<'a> {
|
||||
fn unparse_arg<U>(&mut self, arg: &Arg<U>) {
|
||||
self.p(&arg.node.arg);
|
||||
if let Some(ann) = &arg.node.annotation {
|
||||
write!(self, ": {}", **ann);
|
||||
self.p(": ");
|
||||
self.unparse_expr(ann, precedence::TEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user