Skip to content
Prev Previous commit
Next Next commit
Remove .to_owned() from more files
  • Loading branch information
ShaharNaveh committed Jun 23, 2025
commit 8d7deb2479f98f26a5379f3f2b315b4e3e1696f4
2 changes: 1 addition & 1 deletion vm/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl Packable for f16 {
// "from_f64 should be preferred in any non-`const` context" except it gives the wrong result :/
let f_16 = f16::from_f64_const(f_64);
if f_16.is_infinite() != f_64.is_infinite() {
return Err(vm.new_overflow_error("float too large to pack with e format".to_owned()));
return Err(vm.new_overflow_error("float too large to pack with e format"));
}
f_16.to_bits().pack_int::<E>(data);
Ok(())
Expand Down
12 changes: 5 additions & 7 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ impl ExceptionCtor {
match (self, exc_inst) {
// both are instances; which would we choose?
(Self::Instance(_exc_a), Some(_exc_b)) => {
Err(vm
.new_type_error("instance exception may not have a separate value".to_owned()))
Err(vm.new_type_error("instance exception may not have a separate value"))
}
// if the "type" is an instance and the value isn't, use the "type"
(Self::Instance(exc), None) => Ok(exc),
Expand Down Expand Up @@ -653,7 +652,7 @@ impl PyRef<PyBaseException> {
if !vm.is_none(&state) {
let dict = state
.downcast::<crate::builtins::PyDict>()
.map_err(|_| vm.new_type_error("state is not a dictionary".to_owned()))?;
.map_err(|_| vm.new_type_error("state is not a dictionary"))?;

for (key, value) in &dict {
let key_str = key.str(vm)?;
Expand All @@ -672,7 +671,7 @@ impl Constructor for PyBaseException {

fn py_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
if cls.is(PyBaseException::class(&vm.ctx)) && !args.kwargs.is_empty() {
return Err(vm.new_type_error("BaseException() takes no keyword arguments".to_owned()));
return Err(vm.new_type_error("BaseException() takes no keyword arguments"));
}
PyBaseException::new(args.args, vm)
.into_ref_with_type(vm, cls)
Expand Down Expand Up @@ -1130,7 +1129,7 @@ impl serde::Serialize for SerializeException<'_, '_> {
}

pub fn cstring_error(vm: &VirtualMachine) -> PyBaseExceptionRef {
vm.new_value_error("embedded null character".to_owned())
vm.new_value_error("embedded null character")
}

impl ToPyException for std::ffi::NulError {
Expand Down Expand Up @@ -1334,8 +1333,7 @@ pub(super) mod types {
// Check for any remaining invalid keyword arguments
if let Some(invalid_key) = kwargs.keys().next() {
return Err(vm.new_type_error(format!(
"'{}' is an invalid keyword argument for ImportError",
invalid_key
"'{invalid_key}' is an invalid keyword argument for ImportError"
)));
}

Expand Down
22 changes: 10 additions & 12 deletions vm/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ impl IntoPyException for FormatSpecError {
vm.new_value_error(msg)
}
FormatSpecError::PrecisionNotAllowed => {
vm.new_value_error("Precision not allowed in integer format specifier".to_owned())
vm.new_value_error("Precision not allowed in integer format specifier")
}
FormatSpecError::NotAllowed(s) => {
let msg = format!("{s} not allowed with integer format specifier 'c'");
vm.new_value_error(msg)
}
FormatSpecError::UnableToConvert => {
vm.new_value_error("Unable to convert int to float".to_owned())
vm.new_value_error("Unable to convert int to float")
}
FormatSpecError::CodeNotInRange => {
vm.new_overflow_error("%c arg not in range(0x110000)".to_owned())
vm.new_overflow_error("%c arg not in range(0x110000)")
}
FormatSpecError::NotImplemented(c, s) => {
let msg = format!("Format code '{c}' for object of type '{s}' not implemented yet");
Expand All @@ -52,9 +52,9 @@ impl ToPyException for FormatParseError {
fn to_pyexception(&self, vm: &VirtualMachine) -> PyBaseExceptionRef {
match self {
FormatParseError::UnmatchedBracket => {
vm.new_value_error("expected '}' before end of string".to_owned())
vm.new_value_error("expected '}' before end of string")
}
_ => vm.new_value_error("Unexpected error parsing format string".to_owned()),
_ => vm.new_value_error("Unexpected error parsing format string"),
}
}
}
Expand Down Expand Up @@ -130,30 +130,28 @@ pub(crate) fn format(
FieldType::Auto => {
if seen_index {
return Err(vm.new_value_error(
"cannot switch from manual field specification to automatic field numbering"
.to_owned(),
"cannot switch from manual field specification to automatic field numbering",
));
}
auto_argument_index += 1;
arguments
.args
.get(auto_argument_index - 1)
.cloned()
.ok_or_else(|| vm.new_index_error("tuple index out of range".to_owned()))
.ok_or_else(|| vm.new_index_error("tuple index out of range"))
}
FieldType::Index(index) => {
if auto_argument_index != 0 {
return Err(vm.new_value_error(
"cannot switch from automatic field numbering to manual field specification"
.to_owned(),
"cannot switch from automatic field numbering to manual field specification",
));
}
seen_index = true;
arguments
.args
.get(index)
.cloned()
.ok_or_else(|| vm.new_index_error("tuple index out of range".to_owned()))
.ok_or_else(|| vm.new_index_error("tuple index out of range"))
}
FieldType::Keyword(keyword) => keyword
.as_str()
Expand All @@ -170,7 +168,7 @@ pub(crate) fn format_map(
) -> PyResult<Wtf8Buf> {
format_internal(vm, format, &mut |field_type| match field_type {
FieldType::Auto | FieldType::Index(_) => {
Err(vm.new_value_error("Format string contains positional fields".to_owned()))
Err(vm.new_value_error("Format string contains positional fields"))
}
FieldType::Keyword(keyword) => dict.get_item(&keyword, vm),
})
Expand Down