diff --git a/guide/src/class.md b/guide/src/class.md index bb8cfc80927..ff15cb3b9c8 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -1512,9 +1512,6 @@ struct MyClass { impl pyo3::types::DerefToPyAny for MyClass {} unsafe impl pyo3::type_object::PyTypeInfo for MyClass { - const NAME: &'static str = "MyClass"; - const MODULE: ::std::option::Option<&'static str> = ::std::option::Option::None; - #[inline] fn type_object_raw(py: pyo3::Python<'_>) -> *mut pyo3::ffi::PyTypeObject { ::lazy_type_object() diff --git a/guide/src/migration.md b/guide/src/migration.md index e14f7930d1b..6c1c68a2a5d 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -264,7 +264,7 @@ These should be used instead. Before: -```rust +```rust,ignore # #![allow(deprecated)] # use pyo3::prelude::*; # use pyo3::types::PyNone; @@ -1884,7 +1884,7 @@ Starting with PyO3 0.18, this is deprecated and a future PyO3 version will requi Before, x in the below example would be required to be passed from Python code: -```rust,compile_fail,ignore +```rust,ignore # #![allow(dead_code)] # use pyo3::prelude::*; @@ -1967,7 +1967,7 @@ These are equivalent to calling `collections.abc.Mapping.register(MappingPyClass For example, for a mapping class defined in Rust: -```rust,compile_fail +```rust,ignore use pyo3::prelude::*; use std::collections::HashMap; @@ -1987,7 +1987,7 @@ impl Mapping { You must register the class with `collections.abc.Mapping` before the downcast will work: -```rust,compile_fail +```rust,ignore let m = Py::new(py, Mapping { index }).unwrap(); assert!(m.as_ref(py).downcast::().is_err()); PyMapping::register::(py).unwrap(); @@ -2015,7 +2015,7 @@ This may cause inference errors. Before: -```rust,compile_fail +```rust,ignore # use pyo3::prelude::*; # # fn main() { @@ -2132,7 +2132,7 @@ Migration from `#[pyproto]` to `#[pymethods]` is straightforward; copying the ex Before: -```rust,compile_fail +```rust,ignore use pyo3::prelude::*; use pyo3::class::{PyObjectProtocol, PyIterProtocol}; use pyo3::types::PyString; @@ -2157,7 +2157,7 @@ impl PyIterProtocol for MyClass { After -```rust,compile_fail +```rust,ignore use pyo3::prelude::*; use pyo3::types::PyString; @@ -2238,7 +2238,7 @@ Prior to PyO3 0.16 the `wrap_pymodule!` and `wrap_pyfunction!` macros could use For example, the following code was legal before 0.16, but in 0.16 is rejected because the `wrap_pymodule!` macro cannot access the `private_submodule` function: -```rust,compile_fail +```rust,ignore mod foo { use pyo3::prelude::*; @@ -2348,7 +2348,7 @@ To migrate just move the affected methods from a `#[pyproto]` to a `#[pymethods] Before: -```rust,compile_fail +```rust,ignore use pyo3::prelude::*; use pyo3::class::basic::PyObjectProtocol; @@ -2463,7 +2463,7 @@ Just construct the `Result::Err` variant directly. Before: -```rust,compile_fail +```rust,ignore let result: PyResult<()> = PyErr::new::("error message").into(); ``` @@ -2527,7 +2527,7 @@ Now there is only one way to define the conversion, `IntoPy`, so downstream crat Before: -```rust,compile_fail +```rust,ignore # use pyo3::prelude::*; struct MyPyObjectWrapper(PyObject); @@ -2557,7 +2557,7 @@ Similarly, code which was using the `FromPy` trait can be trivially rewritten to Before: -```rust,compile_fail +```rust,ignore # use pyo3::prelude::*; # Python::with_gil(|py| { let obj = PyObject::from_py(1.234, py); @@ -2645,7 +2645,7 @@ There can be two fixes: Before: - ```rust,compile_fail + ```rust,ignore use pyo3::prelude::*; use std::rc::Rc; use std::cell::RefCell; @@ -2680,7 +2680,7 @@ There can be two fixes: Before: - ```rust,compile_fail + ```rust,ignore use pyo3::prelude::*; #[pyclass] @@ -2714,7 +2714,7 @@ To migrate, just pass a `py` argument to any calls to these methods. Before: -```rust,compile_fail +```rust,ignore # pyo3::Python::attach(|py| { py.None().get_refcnt(); # }) @@ -2743,7 +2743,7 @@ Or if you use `ObjectProtocol` by `use pyo3::prelude::*`, you have to do nothing Before: -```rust,compile_fail,ignore +```rust,ignore use pyo3::ObjectProtocol; # pyo3::Python::with_gil(|py| { @@ -2784,7 +2784,7 @@ While PyO3 itself still requires specialization and nightly Rust, now you don't Before: -```rust,compile_fail +```rust,ignore #[pyclass] struct MyClass {} @@ -2874,7 +2874,7 @@ If you need [`PyRef`] or [`PyRefMut`], just call `.borrow()` or `.borrow_mut()` Before: -```rust,compile_fail +```rust,ignore # use pyo3::prelude::*; # #[pyclass] # struct MyClass {} @@ -2904,7 +2904,7 @@ In addition, you can also extract `&PyCell`, though you rarely need it. Before: -```compile_fail +```rust,ignore let obj: &PyAny = create_obj(); let obj_ref: &MyClass = obj.extract().unwrap(); let obj_ref_mut: &mut MyClass = obj.extract().unwrap(); @@ -2939,7 +2939,7 @@ So if your protocol methods take `&T` or `&mut T` (where `T: PyClass`), please u Before: -```rust,compile_fail +```rust,ignore # use pyo3::prelude::*; # use pyo3::class::PySequenceProtocol; #[pyclass] @@ -2958,7 +2958,7 @@ impl PySequenceProtocol for ByteSequence { After: -```rust,compile_fail +```rust,ignore # use pyo3::prelude::*; # use pyo3::class::PySequenceProtocol; #[pyclass] diff --git a/newsfragments/6519.removed.md b/newsfragments/6519.removed.md new file mode 100644 index 00000000000..87a89050119 --- /dev/null +++ b/newsfragments/6519.removed.md @@ -0,0 +1 @@ +Remove all functionality deprecated in PyO3 0.28. diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 82dbbbdec03..44855a25f7e 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -2300,9 +2300,6 @@ fn impl_pytypeinfo(cls: &Ident, attr: &PyClassArgs, ctx: &Ctx) -> TokenStream { quote! { unsafe impl #pyo3_path::type_object::PyTypeInfo for #cls { - const NAME: &str = ::NAME; - const MODULE: ::core::option::Option<&str> = ::MODULE; - #type_hint #[inline] diff --git a/src/conversions/jiff.rs b/src/conversions/jiff.rs index f752aad49bd..df504b8966b 100644 --- a/src/conversions/jiff.rs +++ b/src/conversions/jiff.rs @@ -19,9 +19,11 @@ //! # Example: Convert a `datetime.datetime` to jiff `Zoned` //! //! ```rust -//! # #![cfg_attr(windows, allow(unused_imports))] +//! # #[cfg(not(windows))] //! # use jiff_02 as jiff; +//! # #[cfg(not(windows))] //! use jiff::{Zoned, SignedDuration, ToSpan}; +//! # #[cfg(not(windows))] //! use pyo3::{Python, PyResult, IntoPyObject, types::PyAnyMethods}; //! //! # #[cfg(windows)] diff --git a/src/exceptions.rs b/src/exceptions.rs index b3d48a9141f..edfad35afeb 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -205,9 +205,6 @@ macro_rules! create_exception_type_object { // SAFETY: macro caller has upheld the safety contracts unsafe impl $crate::type_object::PyTypeInfo for $name { - const NAME: &'static str = stringify!($name); - const MODULE: ::core::option::Option<&'static str> = - ::core::option::Option::Some(stringify!($module)); $crate::create_exception_type_hint!($module, $name); #[inline] diff --git a/src/instance.rs b/src/instance.rs index 55d897dda2c..26a0fd86203 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -2021,129 +2021,6 @@ impl Py { self.bind(py).as_any().call_method0(name).map(Bound::unbind) } - /// Create a `Py` instance by taking ownership of the given FFI pointer. - /// - /// # Safety - /// - /// - `ptr` must be a valid pointer to a Python object (or null, which will cause a panic) - /// - `ptr` must be an owned Python reference, as the `Py` will assume ownership - /// - /// # Panics - /// - /// Panics if `ptr` is null. - #[inline] - #[track_caller] - #[deprecated(note = "use `Bound::from_owned_ptr` instead", since = "0.28.0")] - pub unsafe fn from_owned_ptr(py: Python<'_>, ptr: *mut ffi::PyObject) -> Py { - match NonNull::new(ptr) { - Some(nonnull_ptr) => { - // SAFETY: caller has upheld the safety contract, ptr is known to be non-null - unsafe { Self::from_non_null(nonnull_ptr) } - } - None => panic_on_null(py), - } - } - - /// Create a `Py` instance by taking ownership of the given FFI pointer. - /// - /// If `ptr` is null then the current Python exception is fetched as a [`PyErr`]. - /// - /// # Safety - /// - /// - `ptr` must be a valid pointer to a Python object, or null - /// - a non-null `ptr` must be an owned Python reference, as the `Py` will assume ownership - #[inline] - #[deprecated(note = "use `Bound::from_owned_ptr_or_err` instead", since = "0.28.0")] - pub unsafe fn from_owned_ptr_or_err( - py: Python<'_>, - ptr: *mut ffi::PyObject, - ) -> PyResult> { - match NonNull::new(ptr) { - Some(nonnull_ptr) => Ok( - // SAFETY: caller has upheld the safety contract, ptr is known to be non-null - unsafe { Self::from_non_null(nonnull_ptr) }, - ), - None => Err(PyErr::fetch(py)), - } - } - - /// Create a `Py` instance by taking ownership of the given FFI pointer. - /// - /// If `ptr` is null then `None` is returned. - /// - /// # Safety - /// - /// - `ptr` must be a valid pointer to a Python object, or null - /// - a non-null `ptr` must be an owned Python reference, as the `Py` will assume ownership - #[inline] - #[deprecated(note = "use `Bound::from_owned_ptr_or_opt` instead", since = "0.28.0")] - pub unsafe fn from_owned_ptr_or_opt(_py: Python<'_>, ptr: *mut ffi::PyObject) -> Option { - NonNull::new(ptr).map(|nonnull_ptr| { - // SAFETY: caller has upheld the safety contract - unsafe { Self::from_non_null(nonnull_ptr) } - }) - } - - /// Create a `Py` instance by creating a new reference from the given FFI pointer. - /// - /// # Safety - /// `ptr` must be a pointer to a Python object of type T. - /// - /// # Panics - /// - /// Panics if `ptr` is null. - #[inline] - #[track_caller] - #[deprecated(note = "use `Borrowed::from_borrowed_ptr` instead", since = "0.28.0")] - pub unsafe fn from_borrowed_ptr(py: Python<'_>, ptr: *mut ffi::PyObject) -> Py { - // SAFETY: caller has upheld the safety contract - #[allow(deprecated)] - unsafe { Self::from_borrowed_ptr_or_opt(py, ptr) }.unwrap_or_else(|| panic_on_null(py)) - } - - /// Create a `Py` instance by creating a new reference from the given FFI pointer. - /// - /// If `ptr` is null then the current Python exception is fetched as a `PyErr`. - /// - /// # Safety - /// `ptr` must be a pointer to a Python object of type T. - #[inline] - #[deprecated( - note = "use `Borrowed::from_borrowed_ptr_or_err` instead", - since = "0.28.0" - )] - pub unsafe fn from_borrowed_ptr_or_err( - py: Python<'_>, - ptr: *mut ffi::PyObject, - ) -> PyResult { - // SAFETY: caller has upheld the safety contract - #[allow(deprecated)] - unsafe { Self::from_borrowed_ptr_or_opt(py, ptr) }.ok_or_else(|| PyErr::fetch(py)) - } - - /// Create a `Py` instance by creating a new reference from the given FFI pointer. - /// - /// If `ptr` is null then `None` is returned. - /// - /// # Safety - /// `ptr` must be a pointer to a Python object of type T, or null. - #[inline] - #[deprecated( - note = "use `Borrowed::from_borrowed_ptr_or_opt` instead", - since = "0.28.0" - )] - pub unsafe fn from_borrowed_ptr_or_opt( - _py: Python<'_>, - ptr: *mut ffi::PyObject, - ) -> Option { - NonNull::new(ptr).map(|nonnull_ptr| { - // SAFETY: ptr is a valid python object, thread is attached to the interpreter - unsafe { ffi::Py_INCREF(ptr) }; - // SAFETY: caller has upheld the safety contract, and object was just made owned - unsafe { Self::from_non_null(nonnull_ptr) } - }) - } - /// For internal conversions. /// /// # Safety @@ -2860,16 +2737,9 @@ a = A() Python::attach(|py| { const NULL: *mut ffi::PyObject = core::ptr::null_mut(); - #[expect(deprecated, reason = "Py constructors")] // SAFETY: calling all constructors with null pointer to test panic behavior for constructor in unsafe { [ - (|py| { - Py::::from_owned_ptr(py, NULL); - }) as fn(Python<'_>), - (|py| { - Py::::from_borrowed_ptr(py, NULL); - }) as fn(Python<'_>), (|py| { Bound::from_owned_ptr(py, NULL); }) as fn(Python<'_>), diff --git a/src/sync.rs b/src/sync.rs index 7612edb20f7..ccb136f3992 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -10,12 +10,7 @@ //! //! This module provides synchronization primitives which are able to synchronize under these conditions. use crate::platform::sync::Once; -use crate::{ - Bound, Py, Python, - internal::state::SuspendAttach, - sealed::Sealed, - types::{PyAny, PyString}, -}; +use crate::{Bound, Py, Python, internal::state::SuspendAttach, sealed::Sealed, types::PyString}; #[cfg(all(not(Py_LIMITED_API), Py_3_13))] use core::ops::Deref; use core::{cell::UnsafeCell, marker::PhantomData, mem::MaybeUninit}; @@ -29,30 +24,6 @@ pub(crate) mod once_lock; #[cfg(all(not(Py_LIMITED_API), Py_3_13, wip_feature_std))] pub use self::mutex::{PyMutex, PyMutexGuard}; - -/// Deprecated alias for [`pyo3::sync::critical_section::with_critical_section`][crate::sync::critical_section::with_critical_section] -#[deprecated( - since = "0.28.0", - note = "use pyo3::sync::critical_section::with_critical_section instead" -)] -pub fn with_critical_section(object: &Bound<'_, PyAny>, f: F) -> R -where - F: FnOnce() -> R, -{ - crate::sync::critical_section::with_critical_section(object, f) -} - -/// Deprecated alias for [`pyo3::sync::critical_section::with_critical_section2`][crate::sync::critical_section::with_critical_section2] -#[deprecated( - since = "0.28.0", - note = "use pyo3::sync::critical_section::with_critical_section2 instead" -)] -pub fn with_critical_section2(a: &Bound<'_, PyAny>, b: &Bound<'_, PyAny>, f: F) -> R -where - F: FnOnce() -> R, -{ - crate::sync::critical_section::with_critical_section2(a, b, f) -} pub use self::once_lock::PyOnceLock; #[deprecated( diff --git a/src/type_object.rs b/src/type_object.rs index 996ae38a444..3947fe2743e 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -42,20 +42,6 @@ pub trait PySizedLayout: PyLayout + Sized {} /// /// `is_exact_type_of` must only return true for objects whose type is exactly `Self`. pub unsafe trait PyTypeInfo: Sized { - /// Class name. - #[deprecated( - since = "0.28.0", - note = "prefer using `::type_object(py).name()` to get the correct runtime value" - )] - const NAME: &'static str; - - /// Module name, if any. - #[deprecated( - since = "0.28.0", - note = "prefer using `::type_object(py).module()` to get the correct runtime value" - )] - const MODULE: Option<&'static str>; - /// Provides the full python type as a type hint. #[cfg(feature = "experimental-inspect")] const TYPE_HINT: PyStaticExpr = type_hint_identifier!("_typeshed", "Incomplete"); diff --git a/src/types/ellipsis.rs b/src/types/ellipsis.rs index 5f183c97533..1e20fa0a00c 100644 --- a/src/types/ellipsis.rs +++ b/src/types/ellipsis.rs @@ -28,9 +28,6 @@ impl PyEllipsis { } unsafe impl PyTypeInfo for PyEllipsis { - const NAME: &'static str = "ellipsis"; - const MODULE: Option<&'static str> = None; - #[cfg(feature = "experimental-inspect")] const TYPE_HINT: PyStaticExpr = type_hint_identifier!("types", "EllipsisType"); diff --git a/src/types/mapping.rs b/src/types/mapping.rs index 3a0616beeb8..b565b00cd8a 100644 --- a/src/types/mapping.rs +++ b/src/types/mapping.rs @@ -24,9 +24,6 @@ pub struct PyMapping(PyAny); pyobject_native_type_named!(PyMapping); unsafe impl PyTypeInfo for PyMapping { - const NAME: &'static str = "Mapping"; - const MODULE: Option<&'static str> = Some("collections.abc"); - #[cfg(feature = "experimental-inspect")] const TYPE_HINT: PyStaticExpr = type_hint_identifier!("collections.abc", "Mapping"); diff --git a/src/types/mod.rs b/src/types/mod.rs index dc1fc729596..c2bf1d6fe07 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -256,8 +256,6 @@ macro_rules! pyobject_native_type_info( ($name:ty, $typeobject:expr, $type_hint_module:expr, $type_hint_name:expr, $module:expr $(, #checkfunction=$checkfunction:path)? $(;$generics:ident)*) => { // SAFETY: macro caller has upheld the safety contracts unsafe impl<$($generics,)*> $crate::type_object::PyTypeInfo for $name { - const NAME: &'static str = stringify!($name); - const MODULE: ::core::option::Option<&'static str> = $module; $crate::pyobject_type_info_type_hint!($type_hint_module, $type_hint_name); #[inline] diff --git a/src/types/none.rs b/src/types/none.rs index 2642aab04a7..d40218a4fa5 100644 --- a/src/types/none.rs +++ b/src/types/none.rs @@ -26,9 +26,6 @@ impl PyNone { } unsafe impl PyTypeInfo for PyNone { - const NAME: &'static str = "NoneType"; - const MODULE: Option<&'static str> = None; - #[cfg(feature = "experimental-inspect")] const TYPE_HINT: PyStaticExpr = PyStaticExpr::Constant { value: PyStaticConstant::None, diff --git a/src/types/notimplemented.rs b/src/types/notimplemented.rs index eb9bda7d3b6..fc94a312a2e 100644 --- a/src/types/notimplemented.rs +++ b/src/types/notimplemented.rs @@ -28,9 +28,6 @@ impl PyNotImplemented { } unsafe impl PyTypeInfo for PyNotImplemented { - const NAME: &'static str = "NotImplementedType"; - const MODULE: Option<&'static str> = None; - #[cfg(feature = "experimental-inspect")] const TYPE_HINT: PyStaticExpr = type_hint_identifier!("types", "NotImplementedType"); diff --git a/src/types/sequence.rs b/src/types/sequence.rs index d17b1fd936d..4b8ea968926 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -23,9 +23,6 @@ pub struct PySequence(PyAny); pyobject_native_type_named!(PySequence); unsafe impl PyTypeInfo for PySequence { - const NAME: &'static str = "Sequence"; - const MODULE: Option<&'static str> = Some("collections.abc"); - #[cfg(feature = "experimental-inspect")] const TYPE_HINT: PyStaticExpr = type_hint_identifier!("collections.abc", "Sequence");