Fix nightly clippy warnings

This commit is contained in:
Jeong YunWon authored and Jeong, YunWon committed 2025-06-15 16:03:46 +09:00
1 parent 4e094eaa55
commit f560b4cbfb
21 files changed
+38 -49

No files matched your search

+2 -2
View File
@@ -197,12 +197,12 @@ fn run_rustpython(vm: &VirtualMachine, run_mode: RunMode) -> PyResult<()> {
}
let res = match run_mode {
RunMode::Command(command) => {
debug!("Running command {}", command);
debug!("Running command {command}");
vm.run_code_string(scope.clone(), &command, "<stdin>".to_owned())
.map(drop)
}
RunMode::Module(module) => {
debug!("Running module {}", module);
debug!("Running module {module}");
vm.run_module(&module)
}
RunMode::InstallPip(installer) => install_pip(installer, scope.clone(), vm),
+1 -1
View File
@@ -152,7 +152,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
continuing_line = false;
let result = match repl.readline(prompt) {
ReadlineResult::Line(line) => {
debug!("You entered {:?}", line);
debug!("You entered {line:?}");
repl.add_history_entry(line.trim_end()).unwrap();
+1 -2
View File
@@ -756,8 +756,7 @@ impl ToPyException for Base64DecodeError {
InvalidLastSymbol(_, PAD) => "Excess data after padding".to_owned(),
InvalidLastSymbol(length, _) => {
format!(
"Invalid base64-encoded string: number of data characters {} cannot be 1 more than a multiple of 4",
length
"Invalid base64-encoded string: number of data characters {length} cannot be 1 more than a multiple of 4"
)
}
// TODO: clean up errors
+3 -6
View File
@@ -347,11 +347,8 @@ mod _csv {
let arg_len = rest.args.len();
if arg_len != 1 {
return Err(vm.new_type_error(
format!(
"field_size_limit() takes at most 1 argument ({} given)",
arg_len
)
.to_string(),
format!("field_size_limit() takes at most 1 argument ({arg_len} given)")
.to_string(),
));
}
let Ok(new_size) = rest.args.first().unwrap().try_int(vm) else {
@@ -701,7 +698,7 @@ mod _csv {
if let Some(dialect) = g.get(name) {
Ok(self.update_py_dialect(*dialect))
} else {
Err(new_csv_error(vm, format!("{} is not registered.", name)))
Err(new_csv_error(vm, format!("{name} is not registered.")))
}
// TODO
// Maybe need to update the obj from HashMap
+2 -2
View File
@@ -363,7 +363,7 @@ impl FormatSpec {
// Loop over all opcodes:
for code in &self.codes {
buffer = &mut buffer[code.pre_padding..];
debug!("code: {:?}", code);
debug!("code: {code:?}");
match code.code {
FormatType::Str => {
let (buf, rest) = buffer.split_at_mut(code.repeat);
@@ -407,7 +407,7 @@ impl FormatSpec {
let mut items = Vec::with_capacity(self.arg_count);
for code in &self.codes {
data = &data[code.pre_padding..];
debug!("unpack code: {:?}", code);
debug!("unpack code: {code:?}");
match code.code {
FormatType::Pad => {
data = &data[code.repeat..];
+2 -3
View File
@@ -66,10 +66,9 @@ impl PyObjectRef {
warnings::warn(
vm.ctx.exceptions.deprecation_warning,
format!(
"__complex__ returned non-complex (type {}). \
"__complex__ returned non-complex (type {ret_class}). \
The ability to return an instance of a strict subclass of complex \
is deprecated, and may be removed in a future version of Python.",
ret_class
is deprecated, and may be removed in a future version of Python."
),
1,
vm,
+2 -4
View File
@@ -53,14 +53,12 @@ impl Constructor for PyBaseObject {
0 => {}
1 => {
return Err(vm.new_type_error(format!(
"class {} without an implementation for abstract method '{}'",
name, methods
"class {name} without an implementation for abstract method '{methods}'"
)));
}
2.. => {
return Err(vm.new_type_error(format!(
"class {} without an implementation for abstract methods '{}'",
name, methods
"class {name} without an implementation for abstract methods '{methods}'"
)));
}
// TODO: remove `allow` when redox build doesn't complain about it
+1 -2
View File
@@ -132,8 +132,7 @@ impl PyProperty {
let func_args_len = func_args.args.len();
let (_owner, name): (PyObjectRef, PyObjectRef) = func_args.bind(vm).map_err(|_e| {
vm.new_type_error(format!(
"__set_name__() takes 2 positional arguments but {} were given",
func_args_len
"__set_name__() takes 2 positional arguments but {func_args_len} were given"
))
})?;
+3 -2
View File
@@ -1,3 +1,4 @@
// cspell:ignore cmeth
/*! Python `super` class.
See also [CPython source code.](https://github.com/python/cpython/blob/50b48572d9a90c5bb36e2bef6179548ea927a35a/Objects/typeobject.c#L7663)
@@ -125,8 +126,8 @@ impl Initializer for PySuper {
(typ, obj)
};
let mut inner = PySuperInner::new(typ, obj, vm)?;
std::mem::swap(&mut inner, &mut zelf.inner.write());
let inner = PySuperInner::new(typ, obj, vm)?;
*zelf.inner.write() = inner;
Ok(())
}
+2 -2
View File
@@ -419,7 +419,7 @@ impl StandardEncoding {
match encoding {
"be" => Some(Self::Utf32Be),
"le" => Some(Self::Utf32Le),
_ => return None,
_ => None,
}
} else {
None
@@ -1116,7 +1116,7 @@ fn replace_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyObjectRe
let replace = replacement_char.repeat(range.end - range.start);
Ok((replace.to_pyobject(vm), range.end))
} else {
return Err(bad_err_type(err, vm));
Err(bad_err_type(err, vm))
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{PyResult, VirtualMachine, compiler, scope::Scope};
pub fn eval(vm: &VirtualMachine, source: &str, scope: Scope, source_path: &str) -> PyResult {
match vm.compile(source, compiler::Mode::Eval, source_path.to_owned()) {
Ok(bytecode) => {
debug!("Code object: {:?}", bytecode);
debug!("Code object: {bytecode:?}");
vm.run_code_obj(bytecode, scope)
}
Err(err) => Err(vm.new_syntax_error(&err, Some(source))),
+3 -3
View File
@@ -206,7 +206,7 @@ impl VirtualMachine {
lineno
)?;
} else if let Some(filename) = maybe_filename {
filename_suffix = format!(" ({})", filename);
filename_suffix = format!(" ({filename})");
}
if let Some(text) = maybe_text {
@@ -215,7 +215,7 @@ impl VirtualMachine {
let l_text = r_text.trim_start_matches([' ', '\n', '\x0c']); // \x0c is \f
let spaces = (r_text.len() - l_text.len()) as isize;
writeln!(output, " {}", l_text)?;
writeln!(output, " {l_text}")?;
let maybe_offset: Option<isize> =
getattr("offset").and_then(|obj| obj.try_to_value::<isize>(vm).ok());
@@ -1615,7 +1615,7 @@ pub(super) mod types {
format!("{} ({}, line {})", msg, basename(filename.as_str()), lineno)
}
(Some(lineno), None) => {
format!("{} (line {})", msg, lineno)
format!("{msg} (line {lineno})")
}
(None, Some(filename)) => {
format!("{} ({})", msg, basename(filename.as_str()))
+1 -1
View File
@@ -1667,7 +1667,7 @@ impl ExecutingFrame<'_> {
.topmost_exception()
.ok_or_else(|| vm.new_runtime_error("No active exception to reraise".to_owned()))?,
};
debug!("Exception raised: {:?} with cause: {:?}", exception, cause);
debug!("Exception raised: {exception:?} with cause: {cause:?}");
if let Some(cause) = cause {
exception.set_cause(cause);
}
+4 -8
View File
@@ -51,8 +51,7 @@ impl PyObject {
Err(err) => return err,
};
vm.new_value_error(format!(
"invalid literal for int() with base {}: {}",
base, repr,
"invalid literal for int() with base {base}: {repr}",
))
})?;
Ok(PyInt::from(i).into_ref(&vm.ctx))
@@ -475,10 +474,9 @@ impl PyNumber<'_> {
warnings::warn(
vm.ctx.exceptions.deprecation_warning,
format!(
"__int__ returned non-int (type {}). \
"__int__ returned non-int (type {ret_class}). \
The ability to return an instance of a strict subclass of int \
is deprecated, and may be removed in a future version of Python.",
ret_class
),
1,
vm,
@@ -509,10 +507,9 @@ impl PyNumber<'_> {
warnings::warn(
vm.ctx.exceptions.deprecation_warning,
format!(
"__index__ returned non-int (type {}). \
"__index__ returned non-int (type {ret_class}). \
The ability to return an instance of a strict subclass of int \
is deprecated, and may be removed in a future version of Python.",
ret_class
),
1,
vm,
@@ -543,10 +540,9 @@ impl PyNumber<'_> {
warnings::warn(
vm.ctx.exceptions.deprecation_warning,
format!(
"__float__ returned non-float (type {}). \
"__float__ returned non-float (type {ret_class}). \
The ability to return an instance of a strict subclass of float \
is deprecated, and may be removed in a future version of Python.",
ret_class
),
1,
vm,
+1 -1
View File
@@ -251,7 +251,7 @@ impl PyCSimple {
#[pyclassmethod]
fn repeat(cls: PyTypeRef, n: isize, vm: &VirtualMachine) -> PyResult {
if n < 0 {
return Err(vm.new_value_error(format!("Array length must be >= 0, not {}", n)));
return Err(vm.new_value_error(format!("Array length must be >= 0, not {n}")));
}
Ok(PyCArrayType {
inner: PyCArray {
+1 -1
View File
@@ -77,7 +77,7 @@ impl Function {
}
})
.collect::<PyResult<Vec<Type>>>()?;
let terminated = format!("{}\0", function);
let terminated = format!("{function}\0");
let pointer: Symbol<'_, FP> = unsafe {
library
.get(terminated.as_bytes())
+1 -1
View File
@@ -53,7 +53,7 @@ impl GetAttr for PyCStructure {
let data = zelf.data.read();
match data.get(&name) {
Some(value) => Ok(value.clone()),
None => Err(vm.new_attribute_error(format!("No attribute named {}", name))),
None => Err(vm.new_attribute_error(format!("No attribute named {name}"))),
}
}
}
+1 -1
View File
@@ -1175,7 +1175,7 @@ mod _io {
vm.call_method(self.raw.as_ref().unwrap(), "readinto", (mem_obj.clone(),));
mem_obj.release();
std::mem::swap(v, &mut read_buf.take());
*v = read_buf.take();
res?
}
+2 -2
View File
@@ -1989,7 +1989,7 @@ pub mod module {
let pathname = vm.ctx.new_dict();
for variant in PathconfVar::iter() {
// get the name of variant as a string to use as the dictionary key
let key = vm.ctx.new_str(format!("{:?}", variant));
let key = vm.ctx.new_str(format!("{variant:?}"));
// get the enum from the string and convert it to an integer for the dictionary value
let value = vm.ctx.new_int(variant as u8);
pathname
@@ -2185,7 +2185,7 @@ pub mod module {
let names = vm.ctx.new_dict();
for variant in SysconfVar::iter() {
// get the name of variant as a string to use as the dictionary key
let key = vm.ctx.new_str(format!("{:?}", variant));
let key = vm.ctx.new_str(format!("{variant:?}"));
// get the enum from the string and convert it to an integer for the dictionary value
let value = vm.ctx.new_int(variant as u8);
names
+3 -3
View File
@@ -317,9 +317,9 @@ mod sys {
let mut source = String::new();
handle
.read_to_string(&mut source)
.map_err(|e| vm.new_os_error(format!("Error reading from stdin: {}", e)))?;
.map_err(|e| vm.new_os_error(format!("Error reading from stdin: {e}")))?;
vm.compile(&source, crate::compiler::Mode::Single, "<stdin>".to_owned())
.map_err(|e| vm.new_os_error(format!("Error running stdin: {}", e)))?;
.map_err(|e| vm.new_os_error(format!("Error running stdin: {e}")))?;
Ok(())
}
@@ -723,7 +723,7 @@ mod sys {
vm.state.int_max_str_digits.store(maxdigits);
Ok(())
} else {
let error = format!("maxdigits must be 0 or larger than {:?}", threshold);
let error = format!("maxdigits must be 0 or larger than {threshold:?}");
Err(vm.new_value_error(error))
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ impl VirtualMachine {
self.run_code_string(scope, &source, path.to_owned())?;
}
Err(err) => {
error!("Failed reading file '{}': {}", path, err);
error!("Failed reading file '{path}': {err}");
// TODO: Need to change to ExitCode or Termination
std::process::exit(1);
}