From f53971e1d063e038f7602f1d1ad398ef1b354f96 Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Sat, 10 Aug 2024 21:11:08 +0200 Subject: [PATCH] reintroduce a bunch of type contructors (#4432) * reintroduce `PyCFunction` constructors * reintroduce `PyIterator` contructors * reintroduce `PyMemoryView` contructors * reintroduce `PyNone` contructors * reintroduce `PyNotImplemented` contructors * reintroduce `PySuper` contructors * reintroduce `PySlice` contructors * reintroduce `PyType` contructors --- pytests/src/buf_and_str.rs | 2 +- src/coroutine.rs | 2 +- src/err/mod.rs | 2 +- src/impl_/wrap.rs | 2 +- src/marker.rs | 4 +-- src/types/any.rs | 4 +-- src/types/frozenset.rs | 2 +- src/types/function.rs | 50 ++++++++++++++++++++++++++++++--- src/types/iterator.rs | 11 ++++++-- src/types/memoryview.rs | 11 ++++++-- src/types/none.rs | 26 +++++++++-------- src/types/notimplemented.rs | 17 +++++++---- src/types/pysuper.rs | 12 +++++++- src/types/set.rs | 2 +- src/types/slice.rs | 24 ++++++++++++---- src/types/typeobject.rs | 9 +++++- tests/test_class_basics.rs | 2 +- tests/test_exceptions.rs | 2 +- tests/test_pyfunction.rs | 16 ++++------- tests/test_super.rs | 2 +- tests/ui/invalid_closure.rs | 2 +- tests/ui/invalid_closure.stderr | 4 +-- 22 files changed, 151 insertions(+), 57 deletions(-) diff --git a/pytests/src/buf_and_str.rs b/pytests/src/buf_and_str.rs index 4a7add32bc2..f9b55efb74f 100644 --- a/pytests/src/buf_and_str.rs +++ b/pytests/src/buf_and_str.rs @@ -44,7 +44,7 @@ impl BytesExtractor { #[pyfunction] fn return_memoryview(py: Python<'_>) -> PyResult> { let bytes = PyBytes::new(py, b"hello world"); - PyMemoryView::from_bound(&bytes) + PyMemoryView::from(&bytes) } #[pymodule] diff --git a/src/coroutine.rs b/src/coroutine.rs index 652292c7892..169d28d635f 100644 --- a/src/coroutine.rs +++ b/src/coroutine.rs @@ -107,7 +107,7 @@ impl Coroutine { if let Some(future) = self.waker.as_ref().unwrap().initialize_future(py)? { // `asyncio.Future` must be awaited; fortunately, it implements `__iter__ = __await__` // and will yield itself if its result has not been set in polling above - if let Some(future) = PyIterator::from_bound_object(&future.as_borrowed()) + if let Some(future) = PyIterator::from_object(&future.as_borrowed()) .unwrap() .next() { diff --git a/src/err/mod.rs b/src/err/mod.rs index 69180cca7b5..3e344c4a66f 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -237,7 +237,7 @@ impl PyErr { /// /// Python::with_gil(|py| { /// let err: PyErr = PyTypeError::new_err(("some type error",)); - /// assert!(err.get_type_bound(py).is(&PyType::new_bound::(py))); + /// assert!(err.get_type_bound(py).is(&PyType::new::(py))); /// }); /// ``` pub fn get_type_bound<'py>(&self, py: Python<'py>) -> Bound<'py, PyType> { diff --git a/src/impl_/wrap.rs b/src/impl_/wrap.rs index 3ab53cf5239..f32faaf5b2b 100644 --- a/src/impl_/wrap.rs +++ b/src/impl_/wrap.rs @@ -74,7 +74,7 @@ impl Deref for UnknownReturnResultType { impl EmptyTupleConverter> { #[inline] pub fn map_into_ptr(&self, py: Python<'_>, obj: PyResult<()>) -> PyResult<*mut ffi::PyObject> { - obj.map(|_| PyNone::get_bound(py).to_owned().into_ptr()) + obj.map(|_| PyNone::get(py).to_owned().into_ptr()) } } diff --git a/src/marker.rs b/src/marker.rs index 84ad22e931c..e2d9a7938ec 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -670,7 +670,7 @@ impl<'py> Python<'py> { #[allow(non_snake_case)] // the Python keyword starts with uppercase #[inline] pub fn None(self) -> PyObject { - PyNone::get_bound(self).into_py(self) + PyNone::get(self).into_py(self) } /// Gets the Python builtin value `Ellipsis`, or `...`. @@ -684,7 +684,7 @@ impl<'py> Python<'py> { #[allow(non_snake_case)] // the Python keyword starts with uppercase #[inline] pub fn NotImplemented(self) -> PyObject { - PyNotImplemented::get_bound(self).into_py(self) + PyNotImplemented::get(self).into_py(self) } /// Gets the running Python interpreter version as a string. diff --git a/src/types/any.rs b/src/types/any.rs index 9ce1f8759e7..72f141eec02 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -1305,7 +1305,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> { } fn iter(&self) -> PyResult> { - PyIterator::from_bound_object(self) + PyIterator::from_object(self) } fn get_type(&self) -> Bound<'py, PyType> { @@ -1466,7 +1466,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> { #[cfg(not(any(PyPy, GraalPy)))] fn py_super(&self) -> PyResult> { - PySuper::new_bound(&self.get_type(), self) + PySuper::new(&self.get_type(), self) } } diff --git a/src/types/frozenset.rs b/src/types/frozenset.rs index b25f0173e4d..6a0cdca89d5 100644 --- a/src/types/frozenset.rs +++ b/src/types/frozenset.rs @@ -200,7 +200,7 @@ pub struct BoundFrozenSetIterator<'p> { impl<'py> BoundFrozenSetIterator<'py> { pub(super) fn new(set: Bound<'py, PyFrozenSet>) -> Self { Self { - it: PyIterator::from_bound_object(&set).unwrap(), + it: PyIterator::from_object(&set).unwrap(), remaining: set.len(), } } diff --git a/src/types/function.rs b/src/types/function.rs index 38d21e32428..8d226a9e792 100644 --- a/src/types/function.rs +++ b/src/types/function.rs @@ -25,7 +25,7 @@ impl PyCFunction { /// /// To create `name` and `doc` static strings on Rust versions older than 1.77 (which added c"" literals), /// use the [`c_str!`](crate::ffi::c_str) macro. - pub fn new_with_keywords_bound<'py>( + pub fn new_with_keywords<'py>( py: Python<'py>, fun: ffi::PyCFunctionWithKeywords, name: &'static CStr, @@ -39,11 +39,24 @@ impl PyCFunction { ) } + /// Deprecated name for [`PyCFunction::new_with_keywords`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyCFunction::new_with_keywords`")] + #[inline] + pub fn new_with_keywords_bound<'py>( + py: Python<'py>, + fun: ffi::PyCFunctionWithKeywords, + name: &'static CStr, + doc: &'static CStr, + module: Option<&Bound<'py, PyModule>>, + ) -> PyResult> { + Self::new_with_keywords(py, fun, name, doc, module) + } + /// Create a new built-in function which takes no arguments. /// /// To create `name` and `doc` static strings on Rust versions older than 1.77 (which added c"" literals), /// use the [`c_str!`](crate::ffi::c_str) macro. - pub fn new_bound<'py>( + pub fn new<'py>( py: Python<'py>, fun: ffi::PyCFunction, name: &'static CStr, @@ -53,6 +66,19 @@ impl PyCFunction { Self::internal_new(py, &PyMethodDef::noargs(name, fun, doc), module) } + /// Deprecated name for [`PyCFunction::new`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyCFunction::new`")] + #[inline] + pub fn new_bound<'py>( + py: Python<'py>, + fun: ffi::PyCFunction, + name: &'static CStr, + doc: &'static CStr, + module: Option<&Bound<'py, PyModule>>, + ) -> PyResult> { + Self::new(py, fun, name, doc, module) + } + /// Create a new function from a closure. /// /// # Examples @@ -66,11 +92,11 @@ impl PyCFunction { /// let i = args.extract::<(i64,)>()?.0; /// Ok(i+1) /// }; - /// let add_one = PyCFunction::new_closure_bound(py, None, None, add_one).unwrap(); + /// let add_one = PyCFunction::new_closure(py, None, None, add_one).unwrap(); /// py_run!(py, add_one, "assert add_one(42) == 43"); /// }); /// ``` - pub fn new_closure_bound<'py, F, R>( + pub fn new_closure<'py, F, R>( py: Python<'py>, name: Option<&'static CStr>, doc: Option<&'static CStr>, @@ -105,6 +131,22 @@ impl PyCFunction { } } + /// Deprecated name for [`PyCFunction::new_closure`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyCFunction::new_closure`")] + #[inline] + pub fn new_closure_bound<'py, F, R>( + py: Python<'py>, + name: Option<&'static CStr>, + doc: Option<&'static CStr>, + closure: F, + ) -> PyResult> + where + F: Fn(&Bound<'_, PyTuple>, Option<&Bound<'_, PyDict>>) -> R + Send + 'static, + R: crate::callback::IntoPyCallbackOutput<*mut ffi::PyObject>, + { + Self::new_closure(py, name, doc, closure) + } + #[doc(hidden)] pub fn internal_new<'py>( py: Python<'py>, diff --git a/src/types/iterator.rs b/src/types/iterator.rs index 453a4882c46..94d0fbf976b 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -35,13 +35,20 @@ impl PyIterator { /// /// Usually it is more convenient to write [`obj.iter()`][crate::types::any::PyAnyMethods::iter], /// which is a more concise way of calling this function. - pub fn from_bound_object<'py>(obj: &Bound<'py, PyAny>) -> PyResult> { + pub fn from_object<'py>(obj: &Bound<'py, PyAny>) -> PyResult> { unsafe { ffi::PyObject_GetIter(obj.as_ptr()) .assume_owned_or_err(obj.py()) .downcast_into_unchecked() } } + + /// Deprecated name for [`PyIterator::from_object`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyIterator::from_object`")] + #[inline] + pub fn from_bound_object<'py>(obj: &Bound<'py, PyAny>) -> PyResult> { + Self::from_object(obj) + } } impl<'py> Iterator for Bound<'py, PyIterator> { @@ -232,7 +239,7 @@ def fibonacci(target): fn int_not_iterable() { Python::with_gil(|py| { let x = 5.to_object(py); - let err = PyIterator::from_bound_object(x.bind(py)).unwrap_err(); + let err = PyIterator::from_object(x.bind(py)).unwrap_err(); assert!(err.is_instance_of::(py)); }); diff --git a/src/types/memoryview.rs b/src/types/memoryview.rs index 22fbb9ba4e2..81acc5cbb2a 100644 --- a/src/types/memoryview.rs +++ b/src/types/memoryview.rs @@ -15,13 +15,20 @@ pyobject_native_type_core!(PyMemoryView, pyobject_native_static_type_object!(ffi impl PyMemoryView { /// Creates a new Python `memoryview` object from another Python object that /// implements the buffer protocol. - pub fn from_bound<'py>(src: &Bound<'py, PyAny>) -> PyResult> { + pub fn from<'py>(src: &Bound<'py, PyAny>) -> PyResult> { unsafe { ffi::PyMemoryView_FromObject(src.as_ptr()) .assume_owned_or_err(src.py()) .downcast_into_unchecked() } } + + /// Deprecated name for [`PyMemoryView::from`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyMemoryView::from`")] + #[inline] + pub fn from_bound<'py>(src: &Bound<'py, PyAny>) -> PyResult> { + Self::from(src) + } } impl<'py> TryFrom<&Bound<'py, PyAny>> for Bound<'py, PyMemoryView> { @@ -30,6 +37,6 @@ impl<'py> TryFrom<&Bound<'py, PyAny>> for Bound<'py, PyMemoryView> { /// Creates a new Python `memoryview` object from another Python object that /// implements the buffer protocol. fn try_from(value: &Bound<'py, PyAny>) -> Result { - PyMemoryView::from_bound(value) + PyMemoryView::from(value) } } diff --git a/src/types/none.rs b/src/types/none.rs index e9846f21969..2a1c54535d7 100644 --- a/src/types/none.rs +++ b/src/types/none.rs @@ -16,9 +16,16 @@ pyobject_native_type_named!(PyNone); impl PyNone { /// Returns the `None` object. #[inline] - pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyNone> { + pub fn get(py: Python<'_>) -> Borrowed<'_, '_, PyNone> { unsafe { ffi::Py_None().assume_borrowed(py).downcast_unchecked() } } + + /// Deprecated name for [`PyNone::get`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyNone::get`")] + #[inline] + pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyNone> { + Self::get(py) + } } unsafe impl PyTypeInfo for PyNone { @@ -38,21 +45,21 @@ unsafe impl PyTypeInfo for PyNone { #[inline] fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool { - object.is(&**Self::get_bound(object.py())) + object.is(&**Self::get(object.py())) } } /// `()` is converted to Python `None`. impl ToPyObject for () { fn to_object(&self, py: Python<'_>) -> PyObject { - PyNone::get_bound(py).into_py(py) + PyNone::get(py).into_py(py) } } impl IntoPy for () { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { - PyNone::get_bound(py).into_py(py) + PyNone::get(py).into_py(py) } } @@ -64,15 +71,15 @@ mod tests { #[test] fn test_none_is_itself() { Python::with_gil(|py| { - assert!(PyNone::get_bound(py).is_instance_of::()); - assert!(PyNone::get_bound(py).is_exact_instance_of::()); + assert!(PyNone::get(py).is_instance_of::()); + assert!(PyNone::get(py).is_exact_instance_of::()); }) } #[test] fn test_none_type_object_consistent() { Python::with_gil(|py| { - assert!(PyNone::get_bound(py) + assert!(PyNone::get(py) .get_type() .is(&PyNone::type_object_bound(py))); }) @@ -81,10 +88,7 @@ mod tests { #[test] fn test_none_is_none() { Python::with_gil(|py| { - assert!(PyNone::get_bound(py) - .downcast::() - .unwrap() - .is_none()); + assert!(PyNone::get(py).downcast::().unwrap().is_none()); }) } diff --git a/src/types/notimplemented.rs b/src/types/notimplemented.rs index 4f8164d39fb..c1c3d1c393a 100644 --- a/src/types/notimplemented.rs +++ b/src/types/notimplemented.rs @@ -15,13 +15,20 @@ pyobject_native_type_named!(PyNotImplemented); impl PyNotImplemented { /// Returns the `NotImplemented` object. #[inline] - pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyNotImplemented> { + pub fn get(py: Python<'_>) -> Borrowed<'_, '_, PyNotImplemented> { unsafe { ffi::Py_NotImplemented() .assume_borrowed(py) .downcast_unchecked() } } + + /// Deprecated name for [`PyNotImplemented::get`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyNotImplemented::get`")] + #[inline] + pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyNotImplemented> { + Self::get(py) + } } unsafe impl PyTypeInfo for PyNotImplemented { @@ -40,7 +47,7 @@ unsafe impl PyTypeInfo for PyNotImplemented { #[inline] fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool { - object.is(&**Self::get_bound(object.py())) + object.is(&**Self::get(object.py())) } } @@ -53,15 +60,15 @@ mod tests { #[test] fn test_notimplemented_is_itself() { Python::with_gil(|py| { - assert!(PyNotImplemented::get_bound(py).is_instance_of::()); - assert!(PyNotImplemented::get_bound(py).is_exact_instance_of::()); + assert!(PyNotImplemented::get(py).is_instance_of::()); + assert!(PyNotImplemented::get(py).is_exact_instance_of::()); }) } #[test] fn test_notimplemented_type_object_consistent() { Python::with_gil(|py| { - assert!(PyNotImplemented::get_bound(py) + assert!(PyNotImplemented::get(py) .get_type() .is(&PyNotImplemented::type_object_bound(py))); }) diff --git a/src/types/pysuper.rs b/src/types/pysuper.rs index 456a3d83e8c..c4e15baca7c 100644 --- a/src/types/pysuper.rs +++ b/src/types/pysuper.rs @@ -57,7 +57,7 @@ impl PySuper { /// } /// } /// ``` - pub fn new_bound<'py>( + pub fn new<'py>( ty: &Bound<'py, PyType>, obj: &Bound<'py, PyAny>, ) -> PyResult> { @@ -68,4 +68,14 @@ impl PySuper { unsafe { any.downcast_into_unchecked() } }) } + + /// Deprecated name for [`PySuper::new`]. + #[deprecated(since = "0.23.0", note = "renamed to `PySuper::new`")] + #[inline] + pub fn new_bound<'py>( + ty: &Bound<'py, PyType>, + obj: &Bound<'py, PyAny>, + ) -> PyResult> { + Self::new(ty, obj) + } } diff --git a/src/types/set.rs b/src/types/set.rs index 4f04a4e4e8f..4bfc45fe80b 100644 --- a/src/types/set.rs +++ b/src/types/set.rs @@ -217,7 +217,7 @@ pub struct BoundSetIterator<'p> { impl<'py> BoundSetIterator<'py> { pub(super) fn new(set: Bound<'py, PySet>) -> Self { Self { - it: PyIterator::from_bound_object(&set).unwrap(), + it: PyIterator::from_object(&set).unwrap(), remaining: set.len(), } } diff --git a/src/types/slice.rs b/src/types/slice.rs index 1e6e0584eae..b9fad06ebdb 100644 --- a/src/types/slice.rs +++ b/src/types/slice.rs @@ -54,7 +54,7 @@ impl PySliceIndices { impl PySlice { /// Constructs a new slice with the given elements. - pub fn new_bound(py: Python<'_>, start: isize, stop: isize, step: isize) -> Bound<'_, PySlice> { + pub fn new(py: Python<'_>, start: isize, stop: isize, step: isize) -> Bound<'_, PySlice> { unsafe { ffi::PySlice_New( ffi::PyLong_FromSsize_t(start), @@ -66,14 +66,28 @@ impl PySlice { } } + /// Deprecated name for [`PySlice::new`]. + #[deprecated(since = "0.23.0", note = "renamed to `PySlice::new`")] + #[inline] + pub fn new_bound(py: Python<'_>, start: isize, stop: isize, step: isize) -> Bound<'_, PySlice> { + Self::new(py, start, stop, step) + } + /// Constructs a new full slice that is equivalent to `::`. - pub fn full_bound(py: Python<'_>) -> Bound<'_, PySlice> { + pub fn full(py: Python<'_>) -> Bound<'_, PySlice> { unsafe { ffi::PySlice_New(ffi::Py_None(), ffi::Py_None(), ffi::Py_None()) .assume_owned(py) .downcast_into_unchecked() } } + + /// Deprecated name for [`PySlice::full`]. + #[deprecated(since = "0.23.0", note = "renamed to `PySlice::full`")] + #[inline] + pub fn full_bound(py: Python<'_>) -> Bound<'_, PySlice> { + Self::full(py) + } } /// Implementation of functionality for [`PySlice`]. @@ -121,7 +135,7 @@ impl<'py> PySliceMethods<'py> for Bound<'py, PySlice> { impl ToPyObject for PySliceIndices { fn to_object(&self, py: Python<'_>) -> PyObject { - PySlice::new_bound(py, self.start, self.stop, self.step).into() + PySlice::new(py, self.start, self.stop, self.step).into() } } @@ -132,7 +146,7 @@ mod tests { #[test] fn test_py_slice_new() { Python::with_gil(|py| { - let slice = PySlice::new_bound(py, isize::MIN, isize::MAX, 1); + let slice = PySlice::new(py, isize::MIN, isize::MAX, 1); assert_eq!( slice.getattr("start").unwrap().extract::().unwrap(), isize::MIN @@ -151,7 +165,7 @@ mod tests { #[test] fn test_py_slice_full() { Python::with_gil(|py| { - let slice = PySlice::full_bound(py); + let slice = PySlice::full(py); assert!(slice.getattr("start").unwrap().is_none(),); assert!(slice.getattr("stop").unwrap().is_none(),); assert!(slice.getattr("step").unwrap().is_none(),); diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index c31dccb565e..bbb1e5ef4cb 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -23,10 +23,17 @@ pyobject_native_type_core!(PyType, pyobject_native_static_type_object!(ffi::PyTy impl PyType { /// Creates a new type object. #[inline] - pub fn new_bound(py: Python<'_>) -> Bound<'_, PyType> { + pub fn new(py: Python<'_>) -> Bound<'_, PyType> { T::type_object_bound(py) } + /// Deprecated name for [`PyType::new`]. + #[deprecated(since = "0.23.0", note = "renamed to `PyType::new`")] + #[inline] + pub fn new_bound(py: Python<'_>) -> Bound<'_, PyType> { + Self::new::(py) + } + /// Converts the given FFI pointer into `Bound`, to use in safe code. /// /// The function creates a new reference from the given pointer, and returns diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index a255cc16de5..cb42e532154 100644 --- a/tests/test_class_basics.rs +++ b/tests/test_class_basics.rs @@ -288,7 +288,7 @@ impl UnsendableChild { fn test_unsendable() -> PyResult<()> { let (keep_obj_here, obj) = Python::with_gil(|py| -> PyResult<_> { - let obj: Py = PyType::new_bound::(py).call1((5,))?.extract()?; + let obj: Py = PyType::new::(py).call1((5,))?.extract()?; // Accessing the value inside this thread should not panic let caught_panic = diff --git a/tests/test_exceptions.rs b/tests/test_exceptions.rs index 4cf866f9a0b..cc823136997 100644 --- a/tests/test_exceptions.rs +++ b/tests/test_exceptions.rs @@ -117,7 +117,7 @@ fn test_write_unraisable() { assert!(object.is_none(py)); let err = PyRuntimeError::new_err("bar"); - err.write_unraisable_bound(py, Some(&PyNotImplemented::get_bound(py))); + err.write_unraisable_bound(py, Some(&PyNotImplemented::get(py))); let (err, object) = capture.borrow_mut(py).capture.take().unwrap(); assert_eq!(err.to_string(), "RuntimeError: bar"); diff --git a/tests/test_pyfunction.rs b/tests/test_pyfunction.rs index 24ef32d6994..4896207b0ab 100644 --- a/tests/test_pyfunction.rs +++ b/tests/test_pyfunction.rs @@ -342,7 +342,7 @@ fn test_pycfunction_new() { ffi::PyLong_FromLong(4200) } - let py_fn = PyCFunction::new_bound( + let py_fn = PyCFunction::new( py, c_fn, c_str!("py_fn"), @@ -409,7 +409,7 @@ fn test_pycfunction_new_with_keywords() { ffi::PyLong_FromLong(foo * bar) } - let py_fn = PyCFunction::new_with_keywords_bound( + let py_fn = PyCFunction::new_with_keywords( py, c_fn, c_str!("py_fn"), @@ -453,13 +453,9 @@ fn test_closure() { Ok(res) }) }; - let closure_py = PyCFunction::new_closure_bound( - py, - Some(c_str!("test_fn")), - Some(c_str!("test_fn doc")), - f, - ) - .unwrap(); + let closure_py = + PyCFunction::new_closure(py, Some(c_str!("test_fn")), Some(c_str!("test_fn doc")), f) + .unwrap(); py_assert!(py, closure_py, "closure_py(42) == [43]"); py_assert!(py, closure_py, "closure_py.__name__ == 'test_fn'"); @@ -483,7 +479,7 @@ fn test_closure_counter() { *counter += 1; Ok(*counter) }; - let counter_py = PyCFunction::new_closure_bound(py, None, None, counter_fn).unwrap(); + let counter_py = PyCFunction::new_closure(py, None, None, counter_fn).unwrap(); py_assert!(py, counter_py, "counter_py() == 1"); py_assert!(py, counter_py, "counter_py() == 2"); diff --git a/tests/test_super.rs b/tests/test_super.rs index 3362ad57814..b64fd57e687 100644 --- a/tests/test_super.rs +++ b/tests/test_super.rs @@ -35,7 +35,7 @@ impl SubClass { } fn method_super_new<'py>(self_: &Bound<'py, Self>) -> PyResult> { - let super_ = PySuper::new_bound(&self_.get_type(), self_)?; + let super_ = PySuper::new(&self_.get_type(), self_)?; super_.call_method("method", (), None) } } diff --git a/tests/ui/invalid_closure.rs b/tests/ui/invalid_closure.rs index eca988f1e57..cb302375934 100644 --- a/tests/ui/invalid_closure.rs +++ b/tests/ui/invalid_closure.rs @@ -11,7 +11,7 @@ fn main() { println!("This is five: {:?}", ref_.len()); Ok(()) }; - PyCFunction::new_closure_bound(py, None, None, closure_fn) + PyCFunction::new_closure(py, None, None, closure_fn) .unwrap() .into() }); diff --git a/tests/ui/invalid_closure.stderr b/tests/ui/invalid_closure.stderr index 890d7640502..4791954f3e1 100644 --- a/tests/ui/invalid_closure.stderr +++ b/tests/ui/invalid_closure.stderr @@ -6,8 +6,8 @@ error[E0597]: `local_data` does not live long enough 7 | let ref_: &[u8] = &local_data; | ^^^^^^^^^^^ borrowed value does not live long enough ... -14 | PyCFunction::new_closure_bound(py, None, None, closure_fn) - | ---------------------------------------------------------- argument requires that `local_data` is borrowed for `'static` +14 | PyCFunction::new_closure(py, None, None, closure_fn) + | ---------------------------------------------------- argument requires that `local_data` is borrowed for `'static` ... 17 | }); | - `local_data` dropped here while still borrowed