Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
<Self as pyo3::impl_::pyclass::PyClassImpl>::lazy_type_object()
Expand Down
42 changes: 21 additions & 21 deletions guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ These should be used instead.

Before:

```rust
```rust,ignore
# #![allow(deprecated)]
# use pyo3::prelude::*;
# use pyo3::types::PyNone;
Expand Down Expand Up @@ -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::*;

Expand Down Expand Up @@ -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;

Expand All @@ -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::<PyMapping>().is_err());
PyMapping::register::<Mapping>(py).unwrap();
Expand Down Expand Up @@ -2015,7 +2015,7 @@ This may cause inference errors.

Before:

```rust,compile_fail
```rust,ignore
# use pyo3::prelude::*;
#
# fn main() {
Expand Down Expand Up @@ -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;
Expand All @@ -2157,7 +2157,7 @@ impl PyIterProtocol for MyClass {

After

```rust,compile_fail
```rust,ignore
use pyo3::prelude::*;
use pyo3::types::PyString;

Expand Down Expand Up @@ -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::*;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -2463,7 +2463,7 @@ Just construct the `Result::Err` variant directly.

Before:

```rust,compile_fail
```rust,ignore
let result: PyResult<()> = PyErr::new::<TypeError, _>("error message").into();
```

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2680,7 +2680,7 @@ There can be two fixes:

Before:

```rust,compile_fail
```rust,ignore
use pyo3::prelude::*;

#[pyclass]
Expand Down Expand Up @@ -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();
# })
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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 {}

Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -2904,7 +2904,7 @@ In addition, you can also extract `&PyCell<T>`, 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();
Expand Down Expand Up @@ -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]
Expand All @@ -2958,7 +2958,7 @@ impl PySequenceProtocol for ByteSequence {

After:

```rust,compile_fail
```rust,ignore
# use pyo3::prelude::*;
# use pyo3::class::PySequenceProtocol;
#[pyclass]
Expand Down
1 change: 1 addition & 0 deletions newsfragments/6519.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove all functionality deprecated in PyO3 0.28.
3 changes: 0 additions & 3 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Self as #pyo3_path::PyClass>::NAME;
const MODULE: ::core::option::Option<&str> = <Self as #pyo3_path::impl_::pyclass::PyClassImpl>::MODULE;

#type_hint

#[inline]
Expand Down
4 changes: 3 additions & 1 deletion src/conversions/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 0 additions & 3 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
130 changes: 0 additions & 130 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,129 +2021,6 @@ impl<T> Py<T> {
self.bind(py).as_any().call_method0(name).map(Bound::unbind)
}

/// Create a `Py<T>` 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<T>` 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<T> {
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<T>` 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<T>` 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<Py<T>> {
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<T>` 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<T>` 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<Self> {
NonNull::new(ptr).map(|nonnull_ptr| {
// SAFETY: caller has upheld the safety contract
unsafe { Self::from_non_null(nonnull_ptr) }
})
}

/// Create a `Py<T>` 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<T> {
// 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<T>` 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<Self> {
// 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<T>` 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<Self> {
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
Expand Down Expand Up @@ -2860,16 +2737,9 @@ a = A()
Python::attach(|py| {
const NULL: *mut ffi::PyObject = core::ptr::null_mut();

#[expect(deprecated, reason = "Py<T> constructors")]
// SAFETY: calling all constructors with null pointer to test panic behavior
for constructor in unsafe {
[
(|py| {
Py::<PyAny>::from_owned_ptr(py, NULL);
}) as fn(Python<'_>),
(|py| {
Py::<PyAny>::from_borrowed_ptr(py, NULL);
}) as fn(Python<'_>),
(|py| {
Bound::from_owned_ptr(py, NULL);
}) as fn(Python<'_>),
Expand Down
Loading
Loading