Skip to content

Fix nightly clippy warnings #5803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ 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);
#[cfg(debug_assertions)]
debug!("You entered {line:?}");

repl.add_history_entry(line.trim_end()).unwrap();

Expand Down
3 changes: 1 addition & 2 deletions stdlib/src/binascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,9 @@ mod _csv {
if !rest.args.is_empty() {
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(),
));
return Err(vm.new_type_error(format!(
"field_size_limit() takes at most 1 argument ({arg_len} given)"
)));
}
let Ok(new_size) = rest.args.first().unwrap().try_int(vm) else {
return Err(vm.new_type_error("limit must be an integer".to_string()));
Expand Down Expand Up @@ -701,7 +697,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
Expand Down
4 changes: 2 additions & 2 deletions vm/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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..];
Expand Down
5 changes: 2 additions & 3 deletions vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions vm/src/builtins/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions vm/src/builtins/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
})?;

Expand Down
5 changes: 3 additions & 2 deletions vm/src/builtins/super.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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(())
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl StandardEncoding {
match encoding {
"be" => Some(Self::Utf32Be),
"le" => Some(Self::Utf32Le),
_ => return None,
_ => None,
}
} else {
None
Expand Down Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion vm/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down
6 changes: 3 additions & 3 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
Expand Down Expand Up @@ -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()))
Expand Down
3 changes: 2 additions & 1 deletion vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,8 @@ 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);
#[cfg(debug_assertions)]
debug!("Exception raised: {exception:?} with cause: {cause:?}");
if let Some(cause) = cause {
exception.set_cause(cause);
}
Expand Down
18 changes: 7 additions & 11 deletions vm/src/protocol/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
is deprecated, and may be removed in a future version of Python."
),
1,
vm,
Expand Down Expand Up @@ -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
is deprecated, and may be removed in a future version of Python."
),
1,
vm,
Expand Down Expand Up @@ -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
is deprecated, and may be removed in a future version of Python."
),
1,
vm,
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/ctypes/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions vm/src/stdlib/ctypes/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libffi::middle::{Arg, Cif, CodePtr, Type};
use libloading::Symbol;
use num_traits::ToPrimitive;
use rustpython_common::lock::PyRwLock;
use std::ffi::CString;
use std::fmt::Debug;

// https://github.com/python/cpython/blob/4f8bb3947cfbc20f970ff9d9531e1132a9e95396/Modules/_ctypes/callproc.c#L15
Expand Down Expand Up @@ -77,10 +78,11 @@ impl Function {
}
})
.collect::<PyResult<Vec<Type>>>()?;
let terminated = format!("{}\0", function);
let c_function_name = CString::new(function)
.map_err(|_| vm.new_value_error("Function name contains null bytes".to_string()))?;
let pointer: Symbol<'_, FP> = unsafe {
library
.get(terminated.as_bytes())
.get(c_function_name.as_bytes())
.map_err(|err| err.to_string())
.map_err(|err| vm.new_attribute_error(err))?
};
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/ctypes/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading