diff --git a/guide/src/conversions/traits.md b/guide/src/conversions/traits.md index fde2e354012..c622bae58d2 100644 --- a/guide/src/conversions/traits.md +++ b/guide/src/conversions/traits.md @@ -13,7 +13,7 @@ fails, so usually you will use something like # use pyo3::types::PyList; # fn main() -> PyResult<()> { # Python::with_gil(|py| { -# let list = PyList::new_bound(py, b"foo"); +# let list = PyList::new(py, b"foo"); let v: Vec = list.extract()?; # assert_eq!(&v, &[102, 111, 111]); # Ok(()) diff --git a/guide/src/exception.md b/guide/src/exception.md index 1a68e24086f..bf979237f01 100644 --- a/guide/src/exception.md +++ b/guide/src/exception.md @@ -80,7 +80,7 @@ use pyo3::types::{PyBool, PyList}; Python::with_gil(|py| { assert!(PyBool::new_bound(py, true).is_instance_of::()); - let list = PyList::new_bound(py, &[1, 2, 3, 4]); + let list = PyList::new(py, &[1, 2, 3, 4]); assert!(!list.is_instance_of::()); assert!(list.is_instance_of::()); }); diff --git a/guide/src/performance.md b/guide/src/performance.md index b3d160fe6b1..fb2288dd566 100644 --- a/guide/src/performance.md +++ b/guide/src/performance.md @@ -108,7 +108,7 @@ This limitation is important to keep in mind when this setting is used, especial ```rust,ignore # use pyo3::prelude::*; # use pyo3::types::PyList; -let numbers: Py = Python::with_gil(|py| PyList::empty_bound(py).unbind()); +let numbers: Py = Python::with_gil(|py| PyList::empty(py).unbind()); Python::with_gil(|py| { numbers.bind(py).append(23).unwrap(); @@ -124,7 +124,7 @@ will abort if the list not explicitly disposed via ```rust # use pyo3::prelude::*; # use pyo3::types::PyList; -let numbers: Py = Python::with_gil(|py| PyList::empty_bound(py).unbind()); +let numbers: Py = Python::with_gil(|py| PyList::empty(py).unbind()); Python::with_gil(|py| { numbers.bind(py).append(23).unwrap(); diff --git a/guide/src/trait-bounds.md b/guide/src/trait-bounds.md index eb67bc42413..434ac7dd968 100644 --- a/guide/src/trait-bounds.md +++ b/guide/src/trait-bounds.md @@ -84,7 +84,7 @@ impl Model for UserModel { Python::with_gil(|py| { self.model .bind(py) - .call_method("set_variables", (PyList::new_bound(py, var),), None) + .call_method("set_variables", (PyList::new(py, var),), None) .unwrap(); }) } @@ -182,7 +182,7 @@ This wrapper will also perform the type conversions between Python and Rust. # println!("Rust calling Python to set the variables"); # Python::with_gil(|py| { # self.model.bind(py) -# .call_method("set_variables", (PyList::new_bound(py, var),), None) +# .call_method("set_variables", (PyList::new(py, var),), None) # .unwrap(); # }) # } @@ -360,7 +360,7 @@ impl Model for UserModel { # println!("Rust calling Python to set the variables"); # Python::with_gil(|py| { # self.model.bind(py) -# .call_method("set_variables", (PyList::new_bound(py, var),), None) +# .call_method("set_variables", (PyList::new(py, var),), None) # .unwrap(); # }) # } @@ -419,7 +419,7 @@ impl Model for UserModel { # println!("Rust calling Python to set the variables"); # Python::with_gil(|py| { # let py_model = self.model.bind(py) -# .call_method("set_variables", (PyList::new_bound(py, var),), None) +# .call_method("set_variables", (PyList::new(py, var),), None) # .unwrap(); # }) # } @@ -517,7 +517,7 @@ impl Model for UserModel { Python::with_gil(|py| { self.model .bind(py) - .call_method("set_variables", (PyList::new_bound(py, var),), None) + .call_method("set_variables", (PyList::new(py, var),), None) .unwrap(); }) } diff --git a/guide/src/types.md b/guide/src/types.md index 5a011ddbe5d..131cb0ed119 100644 --- a/guide/src/types.md +++ b/guide/src/types.md @@ -61,7 +61,7 @@ use pyo3::prelude::*; use pyo3::types::PyList; fn example<'py>(py: Python<'py>) -> PyResult<()> { - let x: Bound<'py, PyList> = PyList::empty_bound(py); + let x: Bound<'py, PyList> = PyList::empty(py); x.append(1)?; let y: Bound<'py, PyList> = x.clone(); // y is a new reference to the same list drop(x); // release the original reference x @@ -77,7 +77,7 @@ use pyo3::prelude::*; use pyo3::types::PyList; fn example(py: Python<'_>) -> PyResult<()> { - let x = PyList::empty_bound(py); + let x = PyList::empty(py); x.append(1)?; let y = x.clone(); drop(x); @@ -232,7 +232,7 @@ fn get_first_item<'py>(list: &Bound<'py, PyList>) -> PyResult> list.get_item(0) } # Python::with_gil(|py| { -# let l = PyList::new_bound(py, ["hello world"]); +# let l = PyList::new(py, ["hello world"]); # assert!(get_first_item(&l).unwrap().eq("hello world").unwrap()); # }) ``` diff --git a/pyo3-benches/benches/bench_frompyobject.rs b/pyo3-benches/benches/bench_frompyobject.rs index f53f116a154..3cb21639b68 100644 --- a/pyo3-benches/benches/bench_frompyobject.rs +++ b/pyo3-benches/benches/bench_frompyobject.rs @@ -25,7 +25,7 @@ fn enum_from_pyobject(b: &mut Bencher<'_>) { fn list_via_downcast(b: &mut Bencher<'_>) { Python::with_gil(|py| { - let any = PyList::empty_bound(py).into_any(); + let any = PyList::empty(py).into_any(); b.iter(|| black_box(&any).downcast::().unwrap()); }) @@ -33,7 +33,7 @@ fn list_via_downcast(b: &mut Bencher<'_>) { fn list_via_extract(b: &mut Bencher<'_>) { Python::with_gil(|py| { - let any = PyList::empty_bound(py).into_any(); + let any = PyList::empty(py).into_any(); b.iter(|| black_box(&any).extract::>().unwrap()); }) diff --git a/pyo3-benches/benches/bench_list.rs b/pyo3-benches/benches/bench_list.rs index dcbdb4779cb..4f6374d75eb 100644 --- a/pyo3-benches/benches/bench_list.rs +++ b/pyo3-benches/benches/bench_list.rs @@ -8,7 +8,7 @@ use pyo3::types::{PyList, PySequence}; fn iter_list(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 100_000; - let list = PyList::new_bound(py, 0..LEN); + let list = PyList::new(py, 0..LEN); let mut sum = 0; b.iter(|| { for x in &list { @@ -22,14 +22,14 @@ fn iter_list(b: &mut Bencher<'_>) { fn list_new(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - b.iter_with_large_drop(|| PyList::new_bound(py, 0..LEN)); + b.iter_with_large_drop(|| PyList::new(py, 0..LEN)); }); } fn list_get_item(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let list = PyList::new_bound(py, 0..LEN); + let list = PyList::new(py, 0..LEN); let mut sum = 0; b.iter(|| { for i in 0..LEN { @@ -43,7 +43,7 @@ fn list_get_item(b: &mut Bencher<'_>) { fn list_get_item_unchecked(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let list = PyList::new_bound(py, 0..LEN); + let list = PyList::new(py, 0..LEN); let mut sum = 0; b.iter(|| { for i in 0..LEN { @@ -58,7 +58,7 @@ fn list_get_item_unchecked(b: &mut Bencher<'_>) { fn sequence_from_list(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; - let list = &PyList::new_bound(py, 0..LEN); + let list = &PyList::new(py, 0..LEN); b.iter(|| black_box(list).downcast::().unwrap()); }); } diff --git a/pyo3-benches/benches/bench_tuple.rs b/pyo3-benches/benches/bench_tuple.rs index 3c0b56a0234..e2985cc998f 100644 --- a/pyo3-benches/benches/bench_tuple.rs +++ b/pyo3-benches/benches/bench_tuple.rs @@ -103,7 +103,7 @@ fn tuple_new_list(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50_000; let tuple = PyTuple::new_bound(py, 0..LEN); - b.iter_with_large_drop(|| PyList::new_bound(py, tuple.iter_borrowed())); + b.iter_with_large_drop(|| PyList::new(py, tuple.iter_borrowed())); }); } diff --git a/src/conversions/smallvec.rs b/src/conversions/smallvec.rs index 96dbfad14b7..80e6b09d611 100644 --- a/src/conversions/smallvec.rs +++ b/src/conversions/smallvec.rs @@ -104,7 +104,7 @@ mod tests { Python::with_gil(|py| { let sv: SmallVec<[u64; 8]> = [1, 2, 3, 4, 5].iter().cloned().collect(); let hso: PyObject = sv.clone().into_py(py); - let l = PyList::new_bound(py, [1, 2, 3, 4, 5]); + let l = PyList::new(py, [1, 2, 3, 4, 5]); assert!(l.eq(hso).unwrap()); }); } @@ -112,7 +112,7 @@ mod tests { #[test] fn test_smallvec_from_py_object() { Python::with_gil(|py| { - let l = PyList::new_bound(py, [1, 2, 3, 4, 5]); + let l = PyList::new(py, [1, 2, 3, 4, 5]); let sv: SmallVec<[u64; 8]> = l.extract().unwrap(); assert_eq!(sv.as_slice(), [1, 2, 3, 4, 5]); }); @@ -135,7 +135,7 @@ mod tests { Python::with_gil(|py| { let sv: SmallVec<[u64; 8]> = [1, 2, 3, 4, 5].iter().cloned().collect(); let hso: PyObject = sv.to_object(py); - let l = PyList::new_bound(py, [1, 2, 3, 4, 5]); + let l = PyList::new(py, [1, 2, 3, 4, 5]); assert!(l.eq(hso).unwrap()); }); } diff --git a/src/lib.rs b/src/lib.rs index fdba3f842e6..16f7200519c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ //! - Types that also have the `'py` lifetime, such as the [`Bound<'py, T>`](Bound) smart pointer, are //! bound to the Python GIL and rely on this to offer their functionality. These types often //! have a [`.py()`](Bound::py) method to get the associated [`Python<'py>`](Python) token. -//! - Functions which depend on the `'py` lifetime, such as [`PyList::new_bound`](types::PyList::new_bound), +//! - Functions which depend on the `'py` lifetime, such as [`PyList::new`](types::PyList::new), //! require a [`Python<'py>`](Python) token as an input. Sometimes the token is passed implicitly by //! taking a [`Bound<'py, T>`](Bound) or other type which is bound to the `'py` lifetime. //! - Traits which depend on the `'py` lifetime, such as [`FromPyObject<'py>`](FromPyObject), usually have diff --git a/src/macros.rs b/src/macros.rs index 79b65c17b45..51c54621850 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -12,7 +12,7 @@ /// use pyo3::{prelude::*, py_run, types::PyList}; /// /// Python::with_gil(|py| { -/// let list = PyList::new_bound(py, &[1, 2, 3]); +/// let list = PyList::new(py, &[1, 2, 3]); /// py_run!(py, list, "assert list == [1, 2, 3]"); /// }); /// ``` diff --git a/src/marker.rs b/src/marker.rs index bc0e22e37e7..c42c9722509 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -882,7 +882,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_bound(py, [1, 2, 3, 4]); + let list = PyList::new(py, [1, 2, 3, 4]); assert_eq!(list.extract::>().unwrap(), vec![1, 2, 3, 4]); }); } @@ -890,7 +890,7 @@ mod tests { #[cfg(not(pyo3_disable_reference_pool))] #[test] fn test_allow_threads_pass_stuff_in() { - let list = Python::with_gil(|py| PyList::new_bound(py, vec!["foo", "bar"]).unbind()); + let list = Python::with_gil(|py| PyList::new(py, vec!["foo", "bar"]).unbind()); let mut v = vec![1, 2, 3]; let a = std::sync::Arc::new(String::from("foo")); diff --git a/src/sync.rs b/src/sync.rs index dee39fdfd83..4c4c8fb5dec 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -87,7 +87,7 @@ unsafe impl Sync for GILProtected where T: Send {} /// /// pub fn get_shared_list(py: Python<'_>) -> &Bound<'_, PyList> { /// LIST_CELL -/// .get_or_init(py, || PyList::empty_bound(py).unbind()) +/// .get_or_init(py, || PyList::empty(py).unbind()) /// .bind(py) /// } /// # Python::with_gil(|py| assert_eq!(get_shared_list(py).len(), 0)); diff --git a/src/tests/hygiene/pymethods.rs b/src/tests/hygiene/pymethods.rs index b6d090d9aa8..5abfc856ea2 100644 --- a/src/tests/hygiene/pymethods.rs +++ b/src/tests/hygiene/pymethods.rs @@ -73,7 +73,7 @@ impl Dummy { fn __delattr__(&mut self, name: ::std::string::String) {} fn __dir__<'py>(&self, py: crate::Python<'py>) -> crate::Bound<'py, crate::types::PyList> { - crate::types::PyList::new_bound(py, ::std::vec![0_u8]) + crate::types::PyList::new(py, ::std::vec![0_u8]) } ////////////////////// diff --git a/src/types/any.rs b/src/types/any.rs index 626feba0856..dd8edd885fb 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -1938,10 +1938,10 @@ class SimpleClass: #[test] fn test_is_empty() { Python::with_gil(|py| { - let empty_list = PyList::empty_bound(py).into_any(); + let empty_list = PyList::empty(py).into_any(); assert!(empty_list.is_empty().unwrap()); - let list = PyList::new_bound(py, vec![1, 2, 3]).into_any(); + let list = PyList::new(py, vec![1, 2, 3]).into_any(); assert!(!list.is_empty().unwrap()); let not_container = 5.to_object(py).into_bound(py); diff --git a/src/types/dict.rs b/src/types/dict.rs index 1c86b291e2d..dd6652a6969 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -605,7 +605,7 @@ mod tests { #[cfg(not(any(PyPy, GraalPy)))] fn test_from_sequence() { Python::with_gil(|py| { - let items = PyList::new_bound(py, vec![("a", 1), ("b", 2)]); + let items = PyList::new(py, vec![("a", 1), ("b", 2)]); let dict = PyDict::from_sequence_bound(&items).unwrap(); assert_eq!( 1, @@ -636,7 +636,7 @@ mod tests { #[cfg(not(any(PyPy, GraalPy)))] fn test_from_sequence_err() { Python::with_gil(|py| { - let items = PyList::new_bound(py, vec!["a", "b"]); + let items = PyList::new(py, vec!["a", "b"]); assert!(PyDict::from_sequence_bound(&items).is_err()); }); } diff --git a/src/types/iterator.rs b/src/types/iterator.rs index dccea94785f..57096ae97da 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -149,7 +149,7 @@ mod tests { let count; let obj = py.eval_bound("object()", None, None).unwrap(); let list = { - let list = PyList::empty_bound(py); + let list = PyList::empty(py); list.append(10).unwrap(); list.append(&obj).unwrap(); count = obj.get_refcnt(); diff --git a/src/types/list.rs b/src/types/list.rs index ae08798f946..f12a621e95c 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -75,7 +75,7 @@ impl PyList { /// # fn main() { /// Python::with_gil(|py| { /// let elements: Vec = vec![0, 1, 2, 3, 4, 5]; - /// let list = PyList::new_bound(py, elements); + /// let list = PyList::new(py, elements); /// assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5]"); /// }); /// # } @@ -87,7 +87,7 @@ impl PyList { /// All standard library structures implement this trait correctly, if they do, so calling this /// function with (for example) [`Vec`]`` or `&[T]` will always succeed. #[track_caller] - pub fn new_bound( + pub fn new( py: Python<'_>, elements: impl IntoIterator, ) -> Bound<'_, PyList> @@ -99,14 +99,36 @@ impl PyList { new_from_iter(py, &mut iter) } + /// Deprecated name for [`PyList::new`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyList::new`")] + #[inline] + #[track_caller] + pub fn new_bound( + py: Python<'_>, + elements: impl IntoIterator, + ) -> Bound<'_, PyList> + where + T: ToPyObject, + U: ExactSizeIterator, + { + Self::new(py, elements) + } + /// Constructs a new empty list. - pub fn empty_bound(py: Python<'_>) -> Bound<'_, PyList> { + pub fn empty(py: Python<'_>) -> Bound<'_, PyList> { unsafe { ffi::PyList_New(0) .assume_owned(py) .downcast_into_unchecked() } } + + /// Deprecated name for [`PyList::empty`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyList::empty`")] + #[inline] + pub fn empty_bound(py: Python<'_>) -> Bound<'_, PyList> { + Self::empty(py) + } } /// Implementation of functionality for [`PyList`]. @@ -133,7 +155,7 @@ pub trait PyListMethods<'py>: crate::sealed::Sealed { /// ``` /// use pyo3::{prelude::*, types::PyList}; /// Python::with_gil(|py| { - /// let list = PyList::new_bound(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::().unwrap(), 2); /// }); @@ -251,7 +273,7 @@ impl<'py> PyListMethods<'py> for Bound<'py, PyList> { /// ``` /// use pyo3::{prelude::*, types::PyList}; /// Python::with_gil(|py| { - /// let list = PyList::new_bound(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::().unwrap(), 2); /// }); @@ -521,7 +543,7 @@ mod tests { #[test] fn test_new() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [2, 3, 5, 7]); + let list = PyList::new(py, [2, 3, 5, 7]); assert_eq!(2, list.get_item(0).unwrap().extract::().unwrap()); assert_eq!(3, list.get_item(1).unwrap().extract::().unwrap()); assert_eq!(5, list.get_item(2).unwrap().extract::().unwrap()); @@ -532,7 +554,7 @@ mod tests { #[test] fn test_len() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [1, 2, 3, 4]); + let list = PyList::new(py, [1, 2, 3, 4]); assert_eq!(4, list.len()); }); } @@ -540,7 +562,7 @@ mod tests { #[test] fn test_get_item() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [2, 3, 5, 7]); + let list = PyList::new(py, [2, 3, 5, 7]); assert_eq!(2, list.get_item(0).unwrap().extract::().unwrap()); assert_eq!(3, list.get_item(1).unwrap().extract::().unwrap()); assert_eq!(5, list.get_item(2).unwrap().extract::().unwrap()); @@ -551,7 +573,7 @@ mod tests { #[test] fn test_get_slice() { Python::with_gil(|py| { - let list = PyList::new_bound(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); @@ -562,7 +584,7 @@ mod tests { #[test] fn test_set_item() { Python::with_gil(|py| { - let list = PyList::new_bound(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.get_item(0).unwrap().extract::().unwrap()); @@ -592,7 +614,7 @@ mod tests { #[test] fn test_insert() { Python::with_gil(|py| { - let list = PyList::new_bound(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()); @@ -612,7 +634,7 @@ mod tests { let cnt; let obj = py.eval_bound("object()", None, None).unwrap(); { - let list = PyList::empty_bound(py); + let list = PyList::empty(py); cnt = obj.get_refcnt(); list.insert(0, &obj).unwrap(); } @@ -624,7 +646,7 @@ mod tests { #[test] fn test_append() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [2]); + let list = PyList::new(py, [2]); list.append(3).unwrap(); assert_eq!(2, list.get_item(0).unwrap().extract::().unwrap()); assert_eq!(3, list.get_item(1).unwrap().extract::().unwrap()); @@ -637,7 +659,7 @@ mod tests { let cnt; let obj = py.eval_bound("object()", None, None).unwrap(); { - let list = PyList::empty_bound(py); + let list = PyList::empty(py); cnt = obj.get_refcnt(); list.append(&obj).unwrap(); } @@ -649,7 +671,7 @@ mod tests { fn test_iter() { Python::with_gil(|py| { let v = vec![2, 3, 5, 7]; - let list = PyList::new_bound(py, &v); + let list = PyList::new(py, &v); let mut idx = 0; for el in list { assert_eq!(v[idx], el.extract::().unwrap()); @@ -709,7 +731,7 @@ mod tests { #[test] fn test_into_iter() { Python::with_gil(|py| { - let list = PyList::new_bound(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::().unwrap()); } @@ -721,7 +743,7 @@ mod tests { use crate::types::any::PyAnyMethods; Python::with_gil(|py| { - let list = PyList::new_bound(py, [1, 2, 3, 4]); + let list = PyList::new(py, [1, 2, 3, 4]); let mut items = vec![]; for item in &list { items.push(item.extract::().unwrap()); @@ -733,7 +755,7 @@ mod tests { #[test] fn test_as_sequence() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [1, 2, 3, 4]); + let list = PyList::new(py, [1, 2, 3, 4]); assert_eq!(list.as_sequence().len().unwrap(), 4); assert_eq!( @@ -750,7 +772,7 @@ mod tests { #[test] fn test_into_sequence() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [1, 2, 3, 4]); + let list = PyList::new(py, [1, 2, 3, 4]); let sequence = list.into_sequence(); @@ -763,7 +785,7 @@ mod tests { fn test_extract() { Python::with_gil(|py| { let v = vec![2, 3, 5, 7]; - let list = PyList::new_bound(py, &v); + let list = PyList::new(py, &v); let v2 = list.as_ref().extract::>().unwrap(); assert_eq!(v, v2); }); @@ -773,7 +795,7 @@ mod tests { fn test_sort() { Python::with_gil(|py| { let v = vec![7, 3, 2, 5]; - let list = PyList::new_bound(py, &v); + let list = PyList::new(py, &v); assert_eq!(7, list.get_item(0).unwrap().extract::().unwrap()); assert_eq!(3, list.get_item(1).unwrap().extract::().unwrap()); assert_eq!(2, list.get_item(2).unwrap().extract::().unwrap()); @@ -790,7 +812,7 @@ mod tests { fn test_reverse() { Python::with_gil(|py| { let v = vec![2, 3, 5, 7]; - let list = PyList::new_bound(py, &v); + let list = PyList::new(py, &v); assert_eq!(2, list.get_item(0).unwrap().extract::().unwrap()); assert_eq!(3, list.get_item(1).unwrap().extract::().unwrap()); assert_eq!(5, list.get_item(2).unwrap().extract::().unwrap()); @@ -816,7 +838,7 @@ mod tests { #[test] fn test_list_get_item_invalid_index() { Python::with_gil(|py| { - let list = PyList::new_bound(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!( @@ -829,7 +851,7 @@ mod tests { #[test] fn test_list_get_item_sanity() { Python::with_gil(|py| { - let list = PyList::new_bound(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::().unwrap(), 2); }); @@ -839,7 +861,7 @@ mod tests { #[test] fn test_list_get_item_unchecked_sanity() { Python::with_gil(|py| { - let list = PyList::new_bound(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::().unwrap(), 2); }); @@ -848,7 +870,7 @@ mod tests { #[test] fn test_list_del_item() { Python::with_gil(|py| { - let list = PyList::new_bound(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.get_item(0).unwrap().extract::().unwrap()); assert!(list.del_item(0).is_ok()); @@ -870,11 +892,11 @@ mod tests { #[test] fn test_list_set_slice() { Python::with_gil(|py| { - let list = PyList::new_bound(py, [1, 1, 2, 3, 5, 8]); - let ins = PyList::new_bound(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_bound(py)).unwrap(); + list.set_slice(3, 100, &PyList::empty(py)).unwrap(); assert_eq!([1, 7, 4], list.extract::<[i32; 3]>().unwrap()); }); } @@ -882,7 +904,7 @@ mod tests { #[test] fn test_list_del_slice() { Python::with_gil(|py| { - let list = PyList::new_bound(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(); @@ -893,7 +915,7 @@ mod tests { #[test] fn test_list_contains() { Python::with_gil(|py| { - let list = PyList::new_bound(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); @@ -910,7 +932,7 @@ mod tests { #[test] fn test_list_index() { Python::with_gil(|py| { - let list = PyList::new_bound(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()); @@ -947,7 +969,7 @@ mod tests { fn too_long_iterator() { Python::with_gil(|py| { let iter = FaultyIter(0..usize::MAX, 73); - let _list = PyList::new_bound(py, iter); + let _list = PyList::new(py, iter); }) } @@ -958,7 +980,7 @@ mod tests { fn too_short_iterator() { Python::with_gil(|py| { let iter = FaultyIter(0..35, 73); - let _list = PyList::new_bound(py, iter); + let _list = PyList::new(py, iter); }) } @@ -970,7 +992,7 @@ mod tests { Python::with_gil(|py| { let iter = FaultyIter(0..0, usize::MAX); - let _list = PyList::new_bound(py, iter); + let _list = PyList::new(py, iter); }) } @@ -1029,7 +1051,7 @@ mod tests { Python::with_gil(|py| { std::panic::catch_unwind(|| { let iter = FaultyIter(0..50, 50); - let _list = PyList::new_bound(py, iter); + let _list = PyList::new(py, iter); }) .unwrap_err(); }); @@ -1044,7 +1066,7 @@ mod tests { #[test] fn test_list_to_tuple() { Python::with_gil(|py| { - let list = PyList::new_bound(py, vec![1, 2, 3]); + let list = PyList::new(py, vec![1, 2, 3]); let tuple = list.to_tuple(); let tuple_expected = PyTuple::new(py, vec![1, 2, 3]); assert!(tuple.eq(tuple_expected).unwrap()); diff --git a/src/types/module.rs b/src/types/module.rs index 6b90e5de197..873d3347fc0 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -368,7 +368,7 @@ impl<'py> PyModuleMethods<'py> for Bound<'py, PyModule> { Ok(idx) => idx.downcast_into().map_err(PyErr::from), Err(err) => { if err.is_instance_of::(self.py()) { - let l = PyList::empty_bound(self.py()); + let l = PyList::empty(self.py()); self.setattr(__all__, &l).map_err(PyErr::from)?; Ok(l) } else { diff --git a/src/types/sequence.rs b/src/types/sequence.rs index 1b71a186b57..530b1969d5d 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -558,7 +558,7 @@ mod tests { let ins = w.to_object(py); seq.set_slice(1, 4, ins.bind(py)).unwrap(); assert_eq!([1, 7, 4, 5, 8], seq.extract::<[i32; 5]>().unwrap()); - seq.set_slice(3, 100, &PyList::empty_bound(py)).unwrap(); + seq.set_slice(3, 100, &PyList::empty(py)).unwrap(); assert_eq!([1, 7, 4], seq.extract::<[i32; 3]>().unwrap()); }); } @@ -704,11 +704,7 @@ mod tests { let v = vec!["foo", "bar"]; let ob = v.to_object(py); let seq = ob.downcast_bound::(py).unwrap(); - assert!(seq - .to_list() - .unwrap() - .eq(PyList::new_bound(py, &v)) - .unwrap()); + assert!(seq.to_list().unwrap().eq(PyList::new(py, &v)).unwrap()); }); } @@ -721,7 +717,7 @@ mod tests { assert!(seq .to_list() .unwrap() - .eq(PyList::new_bound(py, ["f", "o", "o"])) + .eq(PyList::new(py, ["f", "o", "o"])) .unwrap()); }); } diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 3d67a062cde..711922ce3fa 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -1178,7 +1178,7 @@ mod tests { Python::with_gil(|py| { let tuple = PyTuple::new(py, vec![1, 2, 3]); let list = tuple.to_list(); - let list_expected = PyList::new_bound(py, vec![1, 2, 3]); + let list_expected = PyList::new(py, vec![1, 2, 3]); assert!(list.eq(list_expected).unwrap()); }) } diff --git a/tests/test_frompyobject.rs b/tests/test_frompyobject.rs index 9afe22141d2..9d8d81491cc 100644 --- a/tests/test_frompyobject.rs +++ b/tests/test_frompyobject.rs @@ -594,7 +594,7 @@ pub struct TransparentFromPyWith { #[test] fn test_transparent_from_py_with() { Python::with_gil(|py| { - let result = PyList::new_bound(py, [1, 2, 3]) + let result = PyList::new(py, [1, 2, 3]) .extract::() .unwrap(); let expected = TransparentFromPyWith { len: 3 }; diff --git a/tests/test_getter_setter.rs b/tests/test_getter_setter.rs index e3852fcd29a..dcccffd3aa6 100644 --- a/tests/test_getter_setter.rs +++ b/tests/test_getter_setter.rs @@ -54,7 +54,7 @@ impl ClassWithProperties { #[getter] fn get_data_list<'py>(&self, py: Python<'py>) -> Bound<'py, PyList> { - PyList::new_bound(py, [self.num]) + PyList::new(py, [self.num]) } } diff --git a/tests/test_methods.rs b/tests/test_methods.rs index 6888a9b0b14..16c82d0eca0 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -703,7 +703,7 @@ impl MethodWithLifeTime { for _ in 0..set.len() { items.push(set.pop().unwrap()); } - let list = PyList::new_bound(py, items); + let list = PyList::new(py, items); list.sort()?; Ok(list) } diff --git a/tests/test_proto_methods.rs b/tests/test_proto_methods.rs index 06e0d45e4a6..71d8fa6eaad 100644 --- a/tests/test_proto_methods.rs +++ b/tests/test_proto_methods.rs @@ -846,7 +846,7 @@ struct DefaultedContains; #[pymethods] impl DefaultedContains { fn __iter__(&self, py: Python<'_>) -> PyObject { - PyList::new_bound(py, ["a", "b", "c"]) + PyList::new(py, ["a", "b", "c"]) .as_ref() .iter() .unwrap() @@ -860,7 +860,7 @@ struct NoContains; #[pymethods] impl NoContains { fn __iter__(&self, py: Python<'_>) -> PyObject { - PyList::new_bound(py, ["a", "b", "c"]) + PyList::new(py, ["a", "b", "c"]) .as_ref() .iter() .unwrap()