diff --git a/guide/src/class.md b/guide/src/class.md index 3096c9f7842..b9b47420ccb 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -1230,6 +1230,7 @@ struct MyClass { impl pyo3::types::DerefToPyAny for MyClass {} +# #[allow(deprecated)] unsafe impl pyo3::type_object::HasPyGilRef for MyClass { type AsRefTarget = pyo3::PyCell; } diff --git a/guide/src/types.md b/guide/src/types.md index 51ea10f4545..372c6c8632f 100644 --- a/guide/src/types.md +++ b/guide/src/types.md @@ -96,6 +96,7 @@ For a `&PyAny` object reference `any` where the underlying object is a `#[pyclas let obj: &PyAny = Py::new(py, MyClass {})?.into_ref(py); // To &PyCell with PyAny::downcast +# #[allow(deprecated)] let _: &PyCell = obj.downcast()?; // To Py (aka PyObject) with .into() diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 5ec6ac172e6..734b9565a66 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1281,6 +1281,7 @@ fn impl_pytypeinfo( }; quote! { + #[allow(deprecated)] unsafe impl _pyo3::type_object::HasPyGilRef for #cls { type AsRefTarget = _pyo3::PyCell; } diff --git a/src/conversion.rs b/src/conversion.rs index fc407fa5bc8..8f5842417de 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -6,9 +6,9 @@ use crate::pyclass::boolean_struct::False; use crate::type_object::PyTypeInfo; use crate::types::any::PyAnyMethods; use crate::types::PyTuple; -use crate::{ - ffi, gil, Bound, Py, PyAny, PyCell, PyClass, PyNativeType, PyObject, PyRef, PyRefMut, Python, -}; +#[allow(deprecated)] +use crate::PyCell; +use crate::{ffi, gil, Bound, Py, PyAny, PyClass, PyNativeType, PyObject, PyRef, PyRefMut, Python}; use std::ptr::NonNull; /// Returns a borrowed pointer to a Python object. @@ -265,6 +265,7 @@ where } } +#[allow(deprecated)] impl<'py, T> FromPyObject<'py> for &'py PyCell where T: PyClass, @@ -279,6 +280,7 @@ where T: PyClass + Clone, { fn extract(obj: &PyAny) -> PyResult { + #[allow(deprecated)] let cell: &PyCell = obj.downcast()?; Ok(unsafe { cell.try_borrow_unguarded()?.clone() }) } diff --git a/src/conversions/std/array.rs b/src/conversions/std/array.rs index d901ff4e59d..bf21244e3b2 100644 --- a/src/conversions/std/array.rs +++ b/src/conversions/std/array.rs @@ -240,7 +240,7 @@ mod tests { let array: [Foo; 8] = [Foo, Foo, Foo, Foo, Foo, Foo, Foo, Foo]; let pyobject = array.into_py(py); let list = pyobject.downcast_bound::(py).unwrap(); - let _cell: &crate::PyCell = list.get_item(4).unwrap().extract().unwrap(); + let _bound = list.get_item(4).unwrap().downcast::().unwrap(); }); } diff --git a/src/impl_/coroutine.rs b/src/impl_/coroutine.rs index a59eddd0e8f..953dc6f2569 100644 --- a/src/impl_/coroutine.rs +++ b/src/impl_/coroutine.rs @@ -4,12 +4,14 @@ use std::{ ops::{Deref, DerefMut}, }; +#[allow(deprecated)] +use crate::PyCell; use crate::{ coroutine::{cancel::ThrowCallback, Coroutine}, instance::Bound, pyclass::boolean_struct::False, types::PyString, - IntoPy, Py, PyAny, PyCell, PyClass, PyErr, PyObject, PyResult, Python, + IntoPy, Py, PyAny, PyClass, PyErr, PyObject, PyResult, Python, }; pub fn new_coroutine( @@ -33,6 +35,7 @@ where fn get_ptr(obj: &Py) -> *mut T { // SAFETY: Py can be casted as *const PyCell + #[allow(deprecated)] unsafe { &*(obj.as_ptr() as *const PyCell) }.get_ptr() } diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index e2204fabb02..1b5c868cd73 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -1,3 +1,5 @@ +#[allow(deprecated)] +use crate::PyCell; use crate::{ exceptions::{PyAttributeError, PyNotImplementedError, PyRuntimeError, PyValueError}, ffi, @@ -8,8 +10,8 @@ use crate::{ pyclass_init::PyObjectInit, types::any::PyAnyMethods, types::PyBool, - Borrowed, Py, PyAny, PyCell, PyClass, PyErr, PyMethodDefType, PyNativeType, PyResult, - PyTypeInfo, Python, + Borrowed, Py, PyAny, PyClass, PyErr, PyMethodDefType, PyNativeType, PyResult, PyTypeInfo, + Python, }; use std::{ borrow::Cow, @@ -26,12 +28,14 @@ pub use lazy_type_object::LazyTypeObject; /// Gets the offset of the dictionary from the start of the object in bytes. #[inline] pub fn dict_offset() -> ffi::Py_ssize_t { + #[allow(deprecated)] PyCell::::dict_offset() } /// Gets the offset of the weakref list from the start of the object in bytes. #[inline] pub fn weaklist_offset() -> ffi::Py_ssize_t { + #[allow(deprecated)] PyCell::::weaklist_offset() } @@ -1105,6 +1109,7 @@ pub trait PyClassBaseType: Sized { /// /// In the future this will be extended to immutable PyClasses too. impl PyClassBaseType for T { + #[allow(deprecated)] type LayoutAsBase = crate::pycell::PyCell; type BaseNativeType = T::BaseNativeType; type Initializer = crate::pyclass_init::PyClassInitializer; @@ -1113,6 +1118,7 @@ impl PyClassBaseType for T { /// Implementation of tp_dealloc for pyclasses without gc pub(crate) unsafe extern "C" fn tp_dealloc(obj: *mut ffi::PyObject) { + #[allow(deprecated)] crate::impl_::trampoline::dealloc(obj, PyCell::::tp_dealloc) } @@ -1122,6 +1128,7 @@ pub(crate) unsafe extern "C" fn tp_dealloc_with_gc(obj: *mut ffi::Py { ffi::PyObject_GC_UnTrack(obj.cast()); } + #[allow(deprecated)] crate::impl_::trampoline::dealloc(obj, PyCell::::tp_dealloc) } diff --git a/src/impl_/pymethods.rs b/src/impl_/pymethods.rs index 70c95ca0883..c17d1f69ca1 100644 --- a/src/impl_/pymethods.rs +++ b/src/impl_/pymethods.rs @@ -6,9 +6,11 @@ use crate::internal_tricks::extract_c_string; use crate::pycell::{PyBorrowError, PyBorrowMutError}; use crate::pyclass::boolean_struct::False; use crate::types::{any::PyAnyMethods, PyModule, PyType}; +#[allow(deprecated)] +use crate::PyCell; use crate::{ - ffi, Borrowed, Bound, DowncastError, Py, PyAny, PyCell, PyClass, PyErr, PyObject, PyRef, - PyRefMut, PyResult, PyTraverseError, PyTypeCheck, PyVisit, Python, + ffi, Borrowed, Bound, DowncastError, Py, PyAny, PyClass, PyErr, PyObject, PyRef, PyRefMut, + PyResult, PyTraverseError, PyTypeCheck, PyVisit, Python, }; use std::borrow::Cow; use std::ffi::CStr; @@ -518,6 +520,7 @@ impl<'a> From> for &'a PyModule { } } +#[allow(deprecated)] impl<'a, 'py, T: PyClass> From> for &'a PyCell { #[inline] fn from(bound: BoundRef<'a, 'py, T>) -> Self { diff --git a/src/instance.rs b/src/instance.rs index 65c5ee3bc5f..80788c11e58 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1,6 +1,8 @@ use crate::err::{self, PyDowncastError, PyErr, PyResult}; use crate::ffi_ptr_ext::FfiPtrExt; -use crate::pycell::{PyBorrowError, PyBorrowMutError, PyCell}; +#[allow(deprecated)] +use crate::pycell::PyCell; +use crate::pycell::{PyBorrowError, PyBorrowMutError}; use crate::pyclass::boolean_struct::{False, True}; use crate::type_object::HasPyGilRef; use crate::types::{any::PyAnyMethods, string::PyStringMethods, typeobject::PyTypeMethods}; @@ -337,6 +339,7 @@ where unsafe { &*cell.get_ptr() } } + #[allow(deprecated)] pub(crate) fn get_cell(&'py self) -> &'py PyCell { let cell = self.as_ptr().cast::>(); // SAFETY: Bound is known to contain an object which is laid out in memory as a @@ -1190,6 +1193,7 @@ where { let any = self.as_ptr() as *const PyAny; // SAFETY: The class itself is frozen and `Sync` and we do not access anything but `cell.contents.value`. + #[allow(deprecated)] unsafe { let cell: &PyCell = PyNativeType::unchecked_downcast(&*any); &*cell.get_ptr() @@ -1706,6 +1710,7 @@ impl std::convert::From> for Py { } // `&PyCell` can be converted to `Py` +#[allow(deprecated)] impl std::convert::From<&PyCell> for Py where T: PyClass, @@ -2222,8 +2227,6 @@ a = A() #[cfg(feature = "macros")] mod using_macros { - use crate::PyCell; - use super::*; #[crate::pyclass(crate = "crate")] @@ -2285,6 +2288,7 @@ a = A() #[test] #[allow(deprecated)] fn cell_tryfrom() { + use crate::PyCell; use crate::PyTryInto; // More detailed tests of the underlying semantics in pycell.rs Python::with_gil(|py| { diff --git a/src/lib.rs b/src/lib.rs index c2591cec91e..ad69c54acbb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,7 +315,9 @@ pub use crate::gil::GILPool; pub use crate::gil::{prepare_freethreaded_python, with_embedded_python_interpreter}; pub use crate::instance::{Borrowed, Bound, Py, PyNativeType, PyObject}; pub use crate::marker::Python; -pub use crate::pycell::{PyCell, PyRef, PyRefMut}; +#[allow(deprecated)] +pub use crate::pycell::PyCell; +pub use crate::pycell::{PyRef, PyRefMut}; pub use crate::pyclass::PyClass; pub use crate::pyclass_init::PyClassInitializer; pub use crate::type_object::{PyTypeCheck, PyTypeInfo}; diff --git a/src/prelude.rs b/src/prelude.rs index dcf4fe71cdd..ef42b2706e9 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -14,7 +14,9 @@ pub use crate::conversion::{PyTryFrom, PyTryInto}; pub use crate::err::{PyErr, PyResult}; pub use crate::instance::{Borrowed, Bound, Py, PyObject}; pub use crate::marker::Python; -pub use crate::pycell::{PyCell, PyRef, PyRefMut}; +#[allow(deprecated)] +pub use crate::pycell::PyCell; +pub use crate::pycell::{PyRef, PyRefMut}; pub use crate::pyclass_init::PyClassInitializer; pub use crate::types::{PyAny, PyModule}; pub use crate::PyNativeType; diff --git a/src/pycell.rs b/src/pycell.rs index 29fd1b37886..fdc75f36de6 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -62,6 +62,7 @@ //! ) -> *mut pyo3::ffi::PyObject { //! use :: pyo3 as _pyo3; //! _pyo3::impl_::trampoline::noargs(_slf, _args, |py, _slf| { +//! # #[allow(deprecated)] //! let _cell = py //! .from_borrowed_ptr::<_pyo3::PyAny>(_slf) //! .downcast::<_pyo3::PyCell>()?; @@ -153,6 +154,7 @@ //! # pub struct Number { //! # inner: u32, //! # } +//! # #[allow(deprecated)] //! #[pyfunction] //! fn swap_numbers(a: &PyCell, b: &PyCell) { //! // Check that the pointers are unequal @@ -263,6 +265,7 @@ unsafe impl PyLayout for PyCellBase where U: PySizedLayout {} /// ``` /// For more information on how, when and why (not) to use `PyCell` please see the /// [module-level documentation](self). +#[deprecated(since = "0.21.0")] #[repr(C)] pub struct PyCell { ob_base: ::LayoutAsBase, @@ -278,10 +281,12 @@ pub(crate) struct PyCellContents { pub(crate) weakref: T::WeakRef, } +#[allow(deprecated)] unsafe impl PyNativeType for PyCell { type AsRefSource = T; } +#[allow(deprecated)] impl PyCell { /// Makes a new `PyCell` on the Python heap and return the reference to it. /// @@ -539,15 +544,19 @@ impl PyCell { } } +#[allow(deprecated)] impl PyCell { fn borrow_checker(&self) -> &::Checker { T::PyClassMutability::borrow_checker(self) } } +#[allow(deprecated)] unsafe impl PyLayout for PyCell {} +#[allow(deprecated)] impl PySizedLayout for PyCell {} +#[allow(deprecated)] impl PyTypeCheck for PyCell where T: PyClass, @@ -559,24 +568,28 @@ where } } +#[allow(deprecated)] unsafe impl AsPyPointer for PyCell { fn as_ptr(&self) -> *mut ffi::PyObject { (self as *const _) as *mut _ } } +#[allow(deprecated)] impl ToPyObject for &PyCell { fn to_object(&self, py: Python<'_>) -> PyObject { unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) } } } +#[allow(deprecated)] impl AsRef for PyCell { fn as_ref(&self) -> &PyAny { unsafe { self.py().from_borrowed_ptr(self.as_ptr()) } } } +#[allow(deprecated)] impl Deref for PyCell { type Target = PyAny; @@ -585,6 +598,7 @@ impl Deref for PyCell { } } +#[allow(deprecated)] impl fmt::Debug for PyCell { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.try_borrow() { @@ -666,7 +680,10 @@ where U: PyClass, { fn as_ref(&self) -> &T::BaseType { - unsafe { &*self.inner.get_cell().ob_base.get_ptr() } + #[allow(deprecated)] + unsafe { + &*self.inner.get_cell().ob_base.get_ptr() + } } } @@ -806,6 +823,7 @@ impl IntoPy for &'_ PyRef<'_, T> { } } +#[allow(deprecated)] impl<'a, T: PyClass> std::convert::TryFrom<&'a PyCell> for crate::PyRef<'a, T> { type Error = PyBorrowError; fn try_from(cell: &'a crate::PyCell) -> Result { @@ -847,7 +865,10 @@ where U: PyClass, { fn as_ref(&self) -> &T::BaseType { - unsafe { &*self.inner.get_cell().ob_base.get_ptr() } + #[allow(deprecated)] + unsafe { + &*self.inner.get_cell().ob_base.get_ptr() + } } } @@ -857,7 +878,10 @@ where U: PyClass, { fn as_mut(&mut self) -> &mut T::BaseType { - unsafe { &mut *self.inner.get_cell().ob_base.get_ptr() } + #[allow(deprecated)] + unsafe { + &mut *self.inner.get_cell().ob_base.get_ptr() + } } } @@ -960,6 +984,7 @@ unsafe impl<'a, T: PyClass> AsPyPointer for PyRefMut<'a, T> { } } +#[allow(deprecated)] impl<'a, T: PyClass> std::convert::TryFrom<&'a PyCell> for crate::PyRefMut<'a, T> { @@ -1074,6 +1099,7 @@ where } } +#[allow(deprecated)] impl PyCellLayout for PyCell where ::LayoutAsBase: PyCellLayout, diff --git a/src/pycell/impl_.rs b/src/pycell/impl_.rs index 29ba7eda7eb..32fd93c3db6 100644 --- a/src/pycell/impl_.rs +++ b/src/pycell/impl_.rs @@ -5,6 +5,7 @@ use std::cell::Cell; use std::marker::PhantomData; use crate::impl_::pyclass::{PyClassBaseType, PyClassImpl}; +#[allow(deprecated)] use crate::PyCell; use super::{PyBorrowError, PyBorrowMutError}; @@ -156,21 +157,25 @@ impl PyClassBorrowChecker for BorrowChecker { } pub trait GetBorrowChecker { + #[allow(deprecated)] fn borrow_checker(cell: &PyCell) -> &::Checker; } impl> GetBorrowChecker for MutableClass { + #[allow(deprecated)] fn borrow_checker(cell: &PyCell) -> &BorrowChecker { &cell.contents.borrow_checker } } impl> GetBorrowChecker for ImmutableClass { + #[allow(deprecated)] fn borrow_checker(cell: &PyCell) -> &EmptySlot { &cell.contents.borrow_checker } } +#[allow(deprecated)] impl, M: PyClassMutability> GetBorrowChecker for ExtendsMutableAncestor where diff --git a/src/pyclass.rs b/src/pyclass.rs index ebdc52dc217..acc121107e4 100644 --- a/src/pyclass.rs +++ b/src/pyclass.rs @@ -1,7 +1,9 @@ //! `PyClass` and related traits. +#[allow(deprecated)] +use crate::PyCell; use crate::{ - callback::IntoPyCallbackOutput, ffi, impl_::pyclass::PyClassImpl, Bound, IntoPy, PyCell, - PyObject, PyResult, PyTypeInfo, Python, + callback::IntoPyCallbackOutput, ffi, impl_::pyclass::PyClassImpl, Bound, IntoPy, PyObject, + PyResult, PyTypeInfo, Python, }; use std::{cmp::Ordering, os::raw::c_int}; @@ -15,6 +17,7 @@ pub use self::gc::{PyTraverseError, PyVisit}; /// /// The `#[pyclass]` attribute implements this trait for your Rust struct - /// you shouldn't implement this trait directly. +#[allow(deprecated)] pub trait PyClass: PyTypeInfo> + PyClassImpl { /// Whether the pyclass is frozen. /// diff --git a/src/pyclass/create_type_object.rs b/src/pyclass/create_type_object.rs index d0c271cf31a..53bf9fd5192 100644 --- a/src/pyclass/create_type_object.rs +++ b/src/pyclass/create_type_object.rs @@ -1,5 +1,7 @@ use pyo3_ffi::PyType_IS_GC; +#[allow(deprecated)] +use crate::PyCell; use crate::{ exceptions::PyTypeError, ffi, @@ -13,7 +15,7 @@ use crate::{ }, types::typeobject::PyTypeMethods, types::PyType, - Py, PyCell, PyClass, PyGetterDef, PyMethodDefType, PyResult, PySetterDef, PyTypeInfo, Python, + Py, PyClass, PyGetterDef, PyMethodDefType, PyResult, PySetterDef, PyTypeInfo, Python, }; use std::{ borrow::Cow, @@ -79,6 +81,7 @@ where .build(py, name, module, size_of) } + #[allow(deprecated)] unsafe { inner( py, diff --git a/src/pyclass_init.rs b/src/pyclass_init.rs index 94d377a732c..d32f39e5ee6 100644 --- a/src/pyclass_init.rs +++ b/src/pyclass_init.rs @@ -1,7 +1,9 @@ //! Contains initialization utilities for `#[pyclass]`. use crate::callback::IntoPyCallbackOutput; use crate::impl_::pyclass::{PyClassBaseType, PyClassDict, PyClassThreadChecker, PyClassWeakRef}; -use crate::{ffi, Py, PyCell, PyClass, PyErr, PyResult, Python}; +#[allow(deprecated)] +use crate::PyCell; +use crate::{ffi, Py, PyClass, PyErr, PyResult, Python}; use crate::{ ffi::PyTypeObject, pycell::{ @@ -208,6 +210,7 @@ impl PyClassInitializer { /// Creates a new PyCell and initializes it. #[doc(hidden)] + #[allow(deprecated)] pub fn create_cell(self, py: Python<'_>) -> PyResult<*mut PyCell> where T: PyClass, @@ -221,6 +224,7 @@ impl PyClassInitializer { /// # Safety /// `subtype` must be a valid pointer to the type object of T or a subclass. #[doc(hidden)] + #[allow(deprecated)] pub unsafe fn create_cell_from_subtype( self, py: Python<'_>, diff --git a/src/types/pysuper.rs b/src/types/pysuper.rs index 261a91f289b..0f1a47444d6 100644 --- a/src/types/pysuper.rs +++ b/src/types/pysuper.rs @@ -62,7 +62,7 @@ impl PySuper { /// (SubClass {}, BaseClass::new()) /// } /// - /// fn method(self_: &PyCell) -> PyResult<&PyAny> { + /// fn method<'py>(self_: &Bound<'py, Self>) -> PyResult> { /// let super_ = self_.py_super()?; /// super_.call_method("method", (), None) /// } diff --git a/tests/test_buffer_protocol.rs b/tests/test_buffer_protocol.rs index 85ff6a4004e..dca900808a8 100644 --- a/tests/test_buffer_protocol.rs +++ b/tests/test_buffer_protocol.rs @@ -24,11 +24,11 @@ struct TestBufferClass { #[pymethods] impl TestBufferClass { unsafe fn __getbuffer__( - slf: &PyCell, + slf: Bound<'_, Self>, view: *mut ffi::Py_buffer, flags: c_int, ) -> PyResult<()> { - fill_view_from_readonly_data(view, flags, &slf.borrow().vec, slf) + fill_view_from_readonly_data(view, flags, &slf.borrow().vec, slf.into_any()) } unsafe fn __releasebuffer__(&self, view: *mut ffi::Py_buffer) { @@ -105,12 +105,12 @@ fn test_releasebuffer_unraisable_error() { #[pymethods] impl ReleaseBufferError { unsafe fn __getbuffer__( - slf: &PyCell, + slf: Bound<'_, Self>, view: *mut ffi::Py_buffer, flags: c_int, ) -> PyResult<()> { static BUF_BYTES: &[u8] = b"hello world"; - fill_view_from_readonly_data(view, flags, BUF_BYTES, slf) + fill_view_from_readonly_data(view, flags, BUF_BYTES, slf.into_any()) } unsafe fn __releasebuffer__(&self, _view: *mut ffi::Py_buffer) -> PyResult<()> { @@ -145,7 +145,7 @@ unsafe fn fill_view_from_readonly_data( view: *mut ffi::Py_buffer, flags: c_int, data: &[u8], - owner: &PyAny, + owner: Bound<'_, PyAny>, ) -> PyResult<()> { if view.is_null() { return Err(PyBufferError::new_err("View is null")); diff --git a/tests/test_class_new.rs b/tests/test_class_new.rs index 9e16631bb83..161c60e9489 100644 --- a/tests/test_class_new.rs +++ b/tests/test_class_new.rs @@ -23,7 +23,7 @@ fn empty_class_with_new() { assert!(typeobj .call((), None) .unwrap() - .downcast::>() + .downcast::() .is_ok()); // Calling with arbitrary args or kwargs is not ok @@ -52,7 +52,7 @@ fn unit_class_with_new() { assert!(typeobj .call((), None) .unwrap() - .downcast::>() + .downcast::() .is_ok()); }); } diff --git a/tests/test_pyself.rs b/tests/test_pyself.rs index fa736f68455..901f52de530 100644 --- a/tests/test_pyself.rs +++ b/tests/test_pyself.rs @@ -18,15 +18,18 @@ struct Reader { #[pymethods] impl Reader { - fn clone_ref(slf: &PyCell) -> &PyCell { + fn clone_ref<'a, 'py>(slf: &'a Bound<'py, Self>) -> &'a Bound<'py, Self> { slf } - fn clone_ref_with_py<'py>(slf: &'py PyCell, _py: Python<'py>) -> &'py PyCell { + fn clone_ref_with_py<'a, 'py>( + slf: &'a Bound<'py, Self>, + _py: Python<'py>, + ) -> &'a Bound<'py, Self> { slf } - fn get_iter(slf: &PyCell, keys: Py) -> Iter { + fn get_iter(slf: &Bound<'_, Self>, keys: Py) -> Iter { Iter { - reader: slf.into(), + reader: slf.clone().unbind(), keys, idx: 0, } diff --git a/tests/test_super.rs b/tests/test_super.rs index 8dcedf808a5..3647e7d5b23 100644 --- a/tests/test_super.rs +++ b/tests/test_super.rs @@ -29,14 +29,14 @@ impl SubClass { (SubClass {}, BaseClass::new()) } - fn method(self_: &PyCell) -> PyResult<&PyAny> { + fn method<'py>(self_: &Bound<'py, Self>) -> PyResult> { let super_ = self_.py_super()?; super_.call_method("method", (), None) } - fn method_super_new(self_: &PyCell) -> PyResult<&PyAny> { + fn method_super_new<'py>(self_: &Bound<'py, Self>) -> PyResult> { #[cfg_attr(not(feature = "gil-refs"), allow(deprecated))] - let super_ = PySuper::new(self_.get_type(), self_)?; + let super_ = PySuper::new_bound(&self_.get_type(), self_)?; super_.call_method("method", (), None) } } diff --git a/tests/test_text_signature.rs b/tests/test_text_signature.rs index 6b56999c62f..0b93500db7e 100644 --- a/tests/test_text_signature.rs +++ b/tests/test_text_signature.rs @@ -367,7 +367,7 @@ fn test_methods() { let _ = a; } #[pyo3(text_signature = "($self, b)")] - fn pyself_method(_this: &PyCell, b: i32) { + fn pyself_method(_this: &Bound<'_, Self>, b: i32) { let _ = b; } #[classmethod] diff --git a/tests/test_various.rs b/tests/test_various.rs index 6f1bfd908a7..250f39834d1 100644 --- a/tests/test_various.rs +++ b/tests/test_various.rs @@ -124,7 +124,7 @@ impl PickleSupport { } pub fn __reduce__<'py>( - slf: &'py PyCell, + slf: &Bound<'py, Self>, py: Python<'py>, ) -> PyResult<(PyObject, Bound<'py, PyTuple>, PyObject)> { let cls = slf.to_object(py).getattr(py, "__class__")?; diff --git a/tests/ui/invalid_frozen_pyclass_borrow.rs b/tests/ui/invalid_frozen_pyclass_borrow.rs index aa8969ab1a6..6379a8707c5 100644 --- a/tests/ui/invalid_frozen_pyclass_borrow.rs +++ b/tests/ui/invalid_frozen_pyclass_borrow.rs @@ -29,7 +29,7 @@ fn py_get_of_mutable_class_fails(class: Py) { class.get(); } -fn pyclass_get_of_mutable_class_fails(class: &PyCell) { +fn pyclass_get_of_mutable_class_fails(class: &Bound<'_, MutableBase>) { class.get(); } diff --git a/tests/ui/invalid_frozen_pyclass_borrow.stderr b/tests/ui/invalid_frozen_pyclass_borrow.stderr index 1a8e45964ca..3acfbeb1823 100644 --- a/tests/ui/invalid_frozen_pyclass_borrow.stderr +++ b/tests/ui/invalid_frozen_pyclass_borrow.stderr @@ -67,11 +67,11 @@ error[E0271]: type mismatch resolving `::Frozen == True` 33 | class.get(); | ^^^ expected `True`, found `False` | -note: required by a bound in `pyo3::PyCell::::get` - --> src/pycell.rs +note: required by a bound in `pyo3::Bound::<'py, T>::get` + --> src/instance.rs | | pub fn get(&self) -> &T | --- required by a bound in this associated function | where | T: PyClass + Sync, - | ^^^^^^^^^^^^^ required by this bound in `PyCell::::get` + | ^^^^^^^^^^^^^ required by this bound in `Bound::<'py, T>::get` diff --git a/tests/ui/pyclass_send.rs b/tests/ui/pyclass_send.rs index 533302740d7..2747c2cb3bb 100644 --- a/tests/ui/pyclass_send.rs +++ b/tests/ui/pyclass_send.rs @@ -8,15 +8,15 @@ struct NotThreadSafe { fn main() { let obj = Python::with_gil(|py| { - PyCell::new(py, NotThreadSafe { data: Rc::new(5) }) + Bound::new(py, NotThreadSafe { data: Rc::new(5) }) .unwrap() - .to_object(py) + .unbind(py) }); std::thread::spawn(move || { Python::with_gil(|py| { // Uh oh, moved Rc to a new thread! - let c: &PyCell = obj.as_ref(py).downcast().unwrap(); + let c = obj.bind(py).downcast::().unwrap(); assert_eq!(*c.borrow().data, 5); })