Skip to content

Commit 283ba3f

Browse files
authored
Fix clippy errors (#5134)
* Fix clippy errors * Add news file * Delete newsfragments/5134.fixed.md
1 parent 3a39844 commit 283ba3f

23 files changed

+105
-123
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn configure_pyo3() -> Result<()> {
3838
ensure_auto_initialize_ok(interpreter_config)?;
3939

4040
for cfg in interpreter_config.build_script_outputs() {
41-
println!("{}", cfg)
41+
println!("{cfg}")
4242
}
4343

4444
// Emit cfgs like `invalid_from_utf8_lint`

src/buffer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ mod tests {
702702
buffer.0.suboffsets,
703703
buffer.0.internal
704704
);
705-
let debug_repr = format!("{:?}", buffer);
705+
let debug_repr = format!("{buffer:?}");
706706
assert_eq!(debug_repr, expected);
707707
});
708708
}
@@ -829,8 +829,7 @@ mod tests {
829829
assert_eq!(
830830
ElementType::from_format(cstr),
831831
expected,
832-
"element from format &Cstr: {:?}",
833-
cstr,
832+
"element from format &Cstr: {cstr:?}",
834833
);
835834
}
836835
}

src/conversions/std/array.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ where
110110

111111
fn invalid_sequence_length(expected: usize, actual: usize) -> PyErr {
112112
exceptions::PyValueError::new_err(format!(
113-
"expected a sequence of length {} (got {})",
114-
expected, actual
113+
"expected a sequence of length {expected} (got {actual})"
115114
))
116115
}
117116

src/conversions/std/ipaddr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ mod test_ipaddr {
123123
let pyobj = ip.into_pyobject(py).unwrap();
124124
let repr = pyobj.repr().unwrap();
125125
let repr = repr.to_string_lossy();
126-
assert_eq!(repr, format!("{}('{}')", py_cls, ip));
126+
assert_eq!(repr, format!("{py_cls}('{ip}')"));
127127

128128
let ip2: IpAddr = pyobj.extract().unwrap();
129129
assert_eq!(ip, ip2);

src/conversions/std/num.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ mod test_128bit_integers {
606606
let x_py = x.into_pyobject(py).unwrap();
607607
let locals = PyDict::new(py);
608608
locals.set_item("x_py", &x_py).unwrap();
609-
py.run(&CString::new(format!("assert x_py == {}", x)).unwrap(), None, Some(&locals)).unwrap();
609+
py.run(&CString::new(format!("assert x_py == {x}")).unwrap(), None, Some(&locals)).unwrap();
610610
let roundtripped: i128 = x_py.extract().unwrap();
611611
assert_eq!(x, roundtripped);
612612
})
@@ -622,7 +622,7 @@ mod test_128bit_integers {
622622
let x_py = x.into_pyobject(py).unwrap();
623623
let locals = PyDict::new(py);
624624
locals.set_item("x_py", &x_py).unwrap();
625-
py.run(&CString::new(format!("assert x_py == {}", x)).unwrap(), None, Some(&locals)).unwrap();
625+
py.run(&CString::new(format!("assert x_py == {x}")).unwrap(), None, Some(&locals)).unwrap();
626626
let roundtripped: NonZeroI128 = x_py.extract().unwrap();
627627
assert_eq!(x, roundtripped);
628628
})
@@ -637,7 +637,7 @@ mod test_128bit_integers {
637637
let x_py = x.into_pyobject(py).unwrap();
638638
let locals = PyDict::new(py);
639639
locals.set_item("x_py", &x_py).unwrap();
640-
py.run(&CString::new(format!("assert x_py == {}", x)).unwrap(), None, Some(&locals)).unwrap();
640+
py.run(&CString::new(format!("assert x_py == {x}")).unwrap(), None, Some(&locals)).unwrap();
641641
let roundtripped: u128 = x_py.extract().unwrap();
642642
assert_eq!(x, roundtripped);
643643
})
@@ -653,7 +653,7 @@ mod test_128bit_integers {
653653
let x_py = x.into_pyobject(py).unwrap();
654654
let locals = PyDict::new(py);
655655
locals.set_item("x_py", &x_py).unwrap();
656-
py.run(&CString::new(format!("assert x_py == {}", x)).unwrap(), None, Some(&locals)).unwrap();
656+
py.run(&CString::new(format!("assert x_py == {x}")).unwrap(), None, Some(&locals)).unwrap();
657657
let roundtripped: NonZeroU128 = x_py.extract().unwrap();
658658
assert_eq!(x, roundtripped);
659659
})

src/err/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ mod tests {
155155
let rust_err = io::Error::new(kind, "some error msg");
156156

157157
let py_err: PyErr = rust_err.into();
158-
let py_err_msg = format!("{}: some error msg", expected_ty);
158+
let py_err_msg = format!("{expected_ty}: some error msg");
159159
assert_eq!(py_err.to_string(), py_err_msg);
160160
let py_error_clone = py_err.clone_ref(py);
161161

src/err/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl std::fmt::Debug for PyErr {
671671
// error, but we can't guarantee that the error
672672
// won't have another unformattable traceback inside
673673
// it and we want to avoid an infinite recursion.
674-
format!("<unformattable {:?}>", tb)
674+
format!("<unformattable {tb:?}>")
675675
}
676676
}),
677677
)
@@ -685,7 +685,7 @@ impl std::fmt::Display for PyErr {
685685
Python::with_gil(|py| {
686686
let value = self.value(py);
687687
let type_name = value.get_type().qualname().map_err(|_| std::fmt::Error)?;
688-
write!(f, "{}", type_name)?;
688+
write!(f, "{type_name}")?;
689689
if let Ok(s) = value.str() {
690690
write!(f, ": {}", &s.to_string_lossy())
691691
} else {
@@ -946,7 +946,7 @@ mod tests {
946946
.run(ffi::c_str!("raise Exception('banana')"), None, None)
947947
.expect_err("raising should have given us an error");
948948

949-
let debug_str = format!("{:?}", err);
949+
let debug_str = format!("{err:?}");
950950
assert!(debug_str.starts_with("PyErr { "));
951951
assert!(debug_str.ends_with(" }"));
952952

src/exceptions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ mod tests {
996996
.into_value(py)
997997
.into_bound(py);
998998
assert_eq!(
999-
format!("{:?}", exc),
999+
format!("{exc:?}"),
10001000
exc.repr().unwrap().extract::<String>().unwrap()
10011001
);
10021002
});
@@ -1025,7 +1025,7 @@ mod tests {
10251025
Python::with_gil(|py| {
10261026
let decode_err = PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err).unwrap();
10271027
assert_eq!(
1028-
format!("{:?}", decode_err),
1028+
format!("{decode_err:?}"),
10291029
"UnicodeDecodeError('utf-8', b'fo\\xd8o', 2, 3, 'invalid utf-8')"
10301030
);
10311031

src/impl_/frompyobject.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn extract_traceback(py: Python<'_>, mut error: PyErr) -> String {
3636

3737
let mut error_msg = error.to_string();
3838
while let Some(cause) = error.cause(py) {
39-
write!(&mut error_msg, ", caused by {}", cause).unwrap();
39+
write!(&mut error_msg, ", caused by {cause}").unwrap();
4040
error = cause
4141
}
4242
error_msg
@@ -86,8 +86,7 @@ fn failed_to_extract_struct_field(
8686
field_name: &str,
8787
) -> PyErr {
8888
let new_err = PyTypeError::new_err(format!(
89-
"failed to extract field {}.{}",
90-
struct_name, field_name
89+
"failed to extract field {struct_name}.{field_name}"
9190
));
9291
new_err.set_cause(py, ::std::option::Option::Some(inner_err));
9392
new_err
@@ -136,8 +135,7 @@ fn failed_to_extract_tuple_struct_field(
136135
struct_name: &str,
137136
index: usize,
138137
) -> PyErr {
139-
let new_err =
140-
PyTypeError::new_err(format!("failed to extract field {}.{}", struct_name, index));
138+
let new_err = PyTypeError::new_err(format!("failed to extract field {struct_name}.{index}"));
141139
new_err.set_cause(py, ::std::option::Option::Some(inner_err));
142140
new_err
143141
}

src/impl_/pyclass.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,7 @@ impl ThreadCheckerImpl {
11061106
assert_eq!(
11071107
thread::current().id(),
11081108
self.0,
1109-
"{} is unsendable, but sent to another thread",
1110-
type_name
1109+
"{type_name} is unsendable, but sent to another thread"
11111110
);
11121111
}
11131112

@@ -1118,8 +1117,7 @@ impl ThreadCheckerImpl {
11181117
fn can_drop(&self, py: Python<'_>, type_name: &'static str) -> bool {
11191118
if thread::current().id() != self.0 {
11201119
PyRuntimeError::new_err(format!(
1121-
"{} is unsendable, but is being dropped on another thread",
1122-
type_name
1120+
"{type_name} is unsendable, but is being dropped on another thread"
11231121
))
11241122
.write_unraisable(py, None);
11251123
return false;

0 commit comments

Comments
 (0)