fix clippy warnings uncovered by msrv bump

This commit is contained in:
David Hewitt 2023-06-05 07:08:27 +01:00
parent 1bbd556718
commit 5bc3e6f15e
12 changed files with 45 additions and 48 deletions

View File

@ -13,10 +13,7 @@ fn make_date(py: Python<'_>, year: i32, month: u8, day: u8) -> PyResult<&PyDate>
#[pyfunction]
fn get_date_tuple<'p>(py: Python<'p>, d: &PyDate) -> &'p PyTuple {
PyTuple::new(
py,
&[d.get_year(), d.get_month() as i32, d.get_day() as i32],
)
PyTuple::new(py, [d.get_year(), d.get_month() as i32, d.get_day() as i32])
}
#[pyfunction]
@ -54,7 +51,7 @@ fn time_with_fold<'p>(
fn get_time_tuple<'p>(py: Python<'p>, dt: &PyTime) -> &'p PyTuple {
PyTuple::new(
py,
&[
[
dt.get_hour() as u32,
dt.get_minute() as u32,
dt.get_second() as u32,
@ -67,7 +64,7 @@ fn get_time_tuple<'p>(py: Python<'p>, dt: &PyTime) -> &'p PyTuple {
fn get_time_tuple_fold<'p>(py: Python<'p>, dt: &PyTime) -> &'p PyTuple {
PyTuple::new(
py,
&[
[
dt.get_hour() as u32,
dt.get_minute() as u32,
dt.get_second() as u32,
@ -86,7 +83,7 @@ fn make_delta(py: Python<'_>, days: i32, seconds: i32, microseconds: i32) -> PyR
fn get_delta_tuple<'p>(py: Python<'p>, delta: &PyDelta) -> &'p PyTuple {
PyTuple::new(
py,
&[
[
delta.get_days(),
delta.get_seconds(),
delta.get_microseconds(),
@ -124,7 +121,7 @@ fn make_datetime<'p>(
fn get_datetime_tuple<'p>(py: Python<'p>, dt: &PyDateTime) -> &'p PyTuple {
PyTuple::new(
py,
&[
[
dt.get_year(),
dt.get_month() as i32,
dt.get_day() as i32,
@ -140,7 +137,7 @@ fn get_datetime_tuple<'p>(py: Python<'p>, dt: &PyDateTime) -> &'p PyTuple {
fn get_datetime_tuple_fold<'p>(py: Python<'p>, dt: &PyDateTime) -> &'p PyTuple {
PyTuple::new(
py,
&[
[
dt.get_year(),
dt.get_month() as i32,
dt.get_day() as i32,

View File

@ -667,7 +667,7 @@ mod tests {
#[test]
fn test_try_from_unchecked() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 2, 3]);
let list = PyList::new(py, [1, 2, 3]);
let val = unsafe { <PyList as PyTryFrom>::try_from_unchecked(list.as_ref()) };
assert!(list.is(val));
});

View File

@ -63,7 +63,7 @@ impl ModuleDef {
.import("sys")?
.getattr("implementation")?
.getattr("version")?;
if version.lt(crate::types::PyTuple::new(py, &PYPY_GOOD_VERSION))? {
if version.lt(crate::types::PyTuple::new(py, PYPY_GOOD_VERSION))? {
let warn = py.import("warnings")?.getattr("warn")?;
warn.call1((
"PyPy 3.7 versions older than 7.3.8 are known to have binary \

View File

@ -1049,7 +1049,7 @@ mod tests {
// If allow_threads is implemented correctly, this thread still owns the GIL here
// so the following Python calls should not cause crashes.
let list = PyList::new(py, &[1, 2, 3, 4]);
let list = PyList::new(py, [1, 2, 3, 4]);
assert_eq!(list.extract::<Vec<i32>>().unwrap(), vec![1, 2, 3, 4]);
});
}

View File

@ -196,7 +196,7 @@ impl PyDate {
///
/// This is equivalent to `datetime.date.fromtimestamp`
pub fn from_timestamp(py: Python<'_>, timestamp: i64) -> PyResult<&PyDate> {
let time_tuple = PyTuple::new(py, &[timestamp]);
let time_tuple = PyTuple::new(py, [timestamp]);
// safety ensure that the API is loaded
let _api = ensure_datetime_api(py);

View File

@ -119,7 +119,7 @@ impl PyList {
/// ```
/// use pyo3::{prelude::*, types::PyList};
/// Python::with_gil(|py| {
/// let list = PyList::new(py, &[2, 3, 5, 7]);
/// let list = PyList::new(py, [2, 3, 5, 7]);
/// let obj = list.get_item(0);
/// assert_eq!(obj.unwrap().extract::<i32>().unwrap(), 2);
/// });
@ -351,7 +351,7 @@ mod tests {
#[test]
fn test_new() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
assert_eq!(2, list[0].extract::<i32>().unwrap());
assert_eq!(3, list[1].extract::<i32>().unwrap());
assert_eq!(5, list[2].extract::<i32>().unwrap());
@ -362,7 +362,7 @@ mod tests {
#[test]
fn test_len() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 2, 3, 4]);
let list = PyList::new(py, [1, 2, 3, 4]);
assert_eq!(4, list.len());
});
}
@ -370,7 +370,7 @@ mod tests {
#[test]
fn test_get_item() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
assert_eq!(2, list.get_item(0).unwrap().extract::<i32>().unwrap());
assert_eq!(3, list.get_item(1).unwrap().extract::<i32>().unwrap());
assert_eq!(5, list.get_item(2).unwrap().extract::<i32>().unwrap());
@ -381,7 +381,7 @@ mod tests {
#[test]
fn test_get_slice() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
let slice = list.get_slice(1, 3);
assert_eq!(2, slice.len());
let slice = list.get_slice(1, 7);
@ -392,7 +392,7 @@ mod tests {
#[test]
fn test_set_item() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
let val = 42i32.to_object(py);
let val2 = 42i32.to_object(py);
assert_eq!(2, list[0].extract::<i32>().unwrap());
@ -423,7 +423,7 @@ mod tests {
#[test]
fn test_insert() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
let val = 42i32.to_object(py);
let val2 = 43i32.to_object(py);
assert_eq!(4, list.len());
@ -456,7 +456,7 @@ mod tests {
#[test]
fn test_append() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2]);
let list = PyList::new(py, [2]);
list.append(3).unwrap();
assert_eq!(2, list[0].extract::<i32>().unwrap());
assert_eq!(3, list[1].extract::<i32>().unwrap());
@ -514,7 +514,7 @@ mod tests {
#[test]
fn test_into_iter() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 2, 3, 4]);
let list = PyList::new(py, [1, 2, 3, 4]);
for (i, item) in list.iter().enumerate() {
assert_eq!((i + 1) as i32, item.extract::<i32>().unwrap());
}
@ -578,7 +578,7 @@ mod tests {
#[test]
fn test_list_get_item_invalid_index() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
let obj = list.get_item(5);
assert!(obj.is_err());
assert_eq!(
@ -591,7 +591,7 @@ mod tests {
#[test]
fn test_list_get_item_sanity() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
let obj = list.get_item(0);
assert_eq!(obj.unwrap().extract::<i32>().unwrap(), 2);
});
@ -601,7 +601,7 @@ mod tests {
#[test]
fn test_list_get_item_unchecked_sanity() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5, 7]);
let list = PyList::new(py, [2, 3, 5, 7]);
let obj = unsafe { list.get_item_unchecked(0) };
assert_eq!(obj.extract::<i32>().unwrap(), 2);
});
@ -610,7 +610,7 @@ mod tests {
#[test]
fn test_list_index_trait() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
assert_eq!(2, list[0].extract::<i32>().unwrap());
assert_eq!(3, list[1].extract::<i32>().unwrap());
assert_eq!(5, list[2].extract::<i32>().unwrap());
@ -621,7 +621,7 @@ mod tests {
#[should_panic]
fn test_list_index_trait_panic() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
let _ = &list[7];
});
}
@ -629,7 +629,7 @@ mod tests {
#[test]
fn test_list_index_trait_ranges() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
assert_eq!(vec![3, 5], list[1..3].extract::<Vec<i32>>().unwrap());
assert_eq!(Vec::<i32>::new(), list[3..3].extract::<Vec<i32>>().unwrap());
assert_eq!(vec![3, 5], list[1..].extract::<Vec<i32>>().unwrap());
@ -645,7 +645,7 @@ mod tests {
#[should_panic = "range start index 5 out of range for list of length 3"]
fn test_list_index_trait_range_panic_start() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
list[5..10].extract::<Vec<i32>>().unwrap();
})
}
@ -654,7 +654,7 @@ mod tests {
#[should_panic = "range end index 10 out of range for list of length 3"]
fn test_list_index_trait_range_panic_end() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
list[1..10].extract::<Vec<i32>>().unwrap();
})
}
@ -663,7 +663,7 @@ mod tests {
#[should_panic = "slice index starts at 2 but ends at 1"]
fn test_list_index_trait_range_panic_wrong_order() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
#[allow(clippy::reversed_empty_ranges)]
list[2..1].extract::<Vec<i32>>().unwrap();
})
@ -673,7 +673,7 @@ mod tests {
#[should_panic = "range start index 8 out of range for list of length 3"]
fn test_list_index_trait_range_from_panic() {
Python::with_gil(|py| {
let list = PyList::new(py, &[2, 3, 5]);
let list = PyList::new(py, [2, 3, 5]);
list[8..].extract::<Vec<i32>>().unwrap();
})
}
@ -681,7 +681,7 @@ mod tests {
#[test]
fn test_list_del_item() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 1, 2, 3, 5, 8]);
let list = PyList::new(py, [1, 1, 2, 3, 5, 8]);
assert!(list.del_item(10).is_err());
assert_eq!(1, list[0].extract::<i32>().unwrap());
assert!(list.del_item(0).is_ok());
@ -703,8 +703,8 @@ mod tests {
#[test]
fn test_list_set_slice() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 1, 2, 3, 5, 8]);
let ins = PyList::new(py, &[7, 4]);
let list = PyList::new(py, [1, 1, 2, 3, 5, 8]);
let ins = PyList::new(py, [7, 4]);
list.set_slice(1, 4, ins).unwrap();
assert_eq!([1, 7, 4, 5, 8], list.extract::<[i32; 5]>().unwrap());
list.set_slice(3, 100, PyList::empty(py)).unwrap();
@ -715,7 +715,7 @@ mod tests {
#[test]
fn test_list_del_slice() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 1, 2, 3, 5, 8]);
let list = PyList::new(py, [1, 1, 2, 3, 5, 8]);
list.del_slice(1, 4).unwrap();
assert_eq!([1, 5, 8], list.extract::<[i32; 3]>().unwrap());
list.del_slice(1, 100).unwrap();
@ -726,7 +726,7 @@ mod tests {
#[test]
fn test_list_contains() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 1, 2, 3, 5, 8]);
let list = PyList::new(py, [1, 1, 2, 3, 5, 8]);
assert_eq!(6, list.len());
let bad_needle = 7i32.to_object(py);
@ -743,7 +743,7 @@ mod tests {
#[test]
fn test_list_index() {
Python::with_gil(|py| {
let list = PyList::new(py, &[1, 1, 2, 3, 5, 8]);
let list = PyList::new(py, [1, 1, 2, 3, 5, 8]);
assert_eq!(0, list.index(1i32).unwrap());
assert_eq!(2, list.index(2i32).unwrap());
assert_eq!(3, list.index(3i32).unwrap());

View File

@ -832,7 +832,7 @@ mod tests {
assert!(seq
.to_list()
.unwrap()
.eq(PyList::new(py, &["f", "o", "o"]))
.eq(PyList::new(py, ["f", "o", "o"]))
.unwrap());
#[allow(deprecated)]
{
@ -850,7 +850,7 @@ mod tests {
assert!(seq
.to_tuple()
.unwrap()
.eq(PyTuple::new(py, &["foo", "bar"]))
.eq(PyTuple::new(py, ["foo", "bar"]))
.unwrap());
#[allow(deprecated)]
{

View File

@ -459,7 +459,7 @@ mod tests {
#[test]
fn test_new() {
Python::with_gil(|py| {
let ob = PyTuple::new(py, &[1, 2, 3]);
let ob = PyTuple::new(py, [1, 2, 3]);
assert_eq!(3, ob.len());
let ob: &PyAny = ob.into();
assert_eq!((1, 2, 3), ob.extract().unwrap());
@ -467,7 +467,7 @@ mod tests {
let mut map = HashSet::new();
map.insert(1);
map.insert(2);
PyTuple::new(py, &map);
PyTuple::new(py, map);
});
}
@ -485,7 +485,7 @@ mod tests {
#[test]
fn test_slice() {
Python::with_gil(|py| {
let tup = PyTuple::new(py, &[2, 3, 5, 7]);
let tup = PyTuple::new(py, [2, 3, 5, 7]);
let slice = tup.get_slice(1, 3);
assert_eq!(2, slice.len());
let slice = tup.get_slice(1, 7);

View File

@ -562,7 +562,7 @@ pub struct TransparentFromPyWith {
#[test]
fn test_transparent_from_py_with() {
Python::with_gil(|py| {
let result = TransparentFromPyWith::extract(PyList::new(py, &[1, 2, 3])).unwrap();
let result = TransparentFromPyWith::extract(PyList::new(py, [1, 2, 3])).unwrap();
let expected = TransparentFromPyWith { len: 3 };
assert_eq!(result, expected);

View File

@ -42,7 +42,7 @@ impl ClassWithProperties {
#[getter]
fn get_data_list<'py>(&self, py: Python<'py>) -> &'py PyList {
PyList::new(py, &[self.num])
PyList::new(py, [self.num])
}
}

View File

@ -91,7 +91,7 @@ fn test_basic() {
let module = pyo3::wrap_pymodule!(basic_module)(py);
let cls = py.get_type::<BasicClass>();
let d = pyo3::types::IntoPyDict::into_py_dict(
&[
[
("mod", module.as_ref(py).as_ref()),
("cls", cls.as_ref()),
("a", cls.call1((8,)).unwrap()),

View File

@ -849,7 +849,7 @@ struct DefaultedContains;
#[pymethods]
impl DefaultedContains {
fn __iter__(&self, py: Python<'_>) -> PyObject {
PyList::new(py, &["a", "b", "c"])
PyList::new(py, ["a", "b", "c"])
.as_ref()
.iter()
.unwrap()
@ -863,7 +863,7 @@ struct NoContains;
#[pymethods]
impl NoContains {
fn __iter__(&self, py: Python<'_>) -> PyObject {
PyList::new(py, &["a", "b", "c"])
PyList::new(py, ["a", "b", "c"])
.as_ref()
.iter()
.unwrap()