diff --git a/src/types/list.rs b/src/types/list.rs index c6098e69119..56fdbad02ca 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -206,8 +206,7 @@ mod test { fn test_new() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![2, 3, 5, 7]; - let list = PyList::new(py, &v); + let list = PyList::new(py, [2, 3, 5, 7]); assert_eq!(2, list.get_item(0).extract::().unwrap()); assert_eq!(3, list.get_item(1).extract::().unwrap()); assert_eq!(5, list.get_item(2).extract::().unwrap()); @@ -218,9 +217,7 @@ mod test { fn test_len() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![1, 2, 3, 4]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, [1, 2, 3, 4]); assert_eq!(4, list.len()); } @@ -228,9 +225,7 @@ mod test { fn test_get_item() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![2, 3, 5, 7]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, [2, 3, 5, 7]); assert_eq!(2, list.get_item(0).extract::().unwrap()); assert_eq!(3, list.get_item(1).extract::().unwrap()); assert_eq!(5, list.get_item(2).extract::().unwrap()); @@ -250,9 +245,7 @@ mod test { fn test_set_item() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![2, 3, 5, 7]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, [2, 3, 5, 7]); let val = 42i32.to_object(py); assert_eq!(2, list.get_item(0).extract::().unwrap()); list.set_item(0, val).unwrap(); @@ -282,9 +275,7 @@ mod test { fn test_insert() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![2, 3, 5, 7]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, [2, 3, 5, 7]); let val = 42i32.to_object(py); assert_eq!(4, list.len()); assert_eq!(2, list.get_item(0).extract::().unwrap()); @@ -315,9 +306,7 @@ mod test { fn test_append() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![2]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, [2]); list.append(3).unwrap(); assert_eq!(2, list.get_item(0).extract::().unwrap()); assert_eq!(3, list.get_item(1).extract::().unwrap()); @@ -344,8 +333,7 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); let v = vec![2, 3, 5, 7]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, &v); let mut idx = 0; for el in list.iter() { assert_eq!(v[idx], el.extract::().unwrap()); @@ -358,9 +346,7 @@ mod test { fn test_into_iter() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![1, 2, 3, 4]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, [1, 2, 3, 4]); for (i, item) in list.iter().enumerate() { assert_eq!((i + 1) as i32, item.extract::().unwrap()); } @@ -371,8 +357,7 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); let v = vec![2, 3, 5, 7]; - let ob = v.to_object(py); - let list = ::try_from(ob.as_ref(py)).unwrap(); + let list = PyList::new(py, &v); let v2 = list.as_ref().extract::>().unwrap(); assert_eq!(v, v2); }