Skip to content

Commit c969dd0

Browse files
authored
remove all functionality deprecated in PyO3 0.26 (#5740)
* remove all functionality deprecated in PyO3 0.26 * newsfragment * also remove 0.25 deprecations
1 parent 0fe5ba4 commit c969dd0

12 files changed

Lines changed: 25 additions & 376 deletions

File tree

guide/src/free-threading.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,15 @@ Python::attach(|py| {
225225
});
226226
```
227227

228-
### `GILProtected` is not exposed
228+
### `GILProtected` has been removed
229229

230-
[`GILProtected`] is a (deprecated) PyO3 type that allows mutable access to static data by leveraging the GIL to lock concurrent access from other threads.
231-
In free-threaded Python there is no GIL, so you will need to replace this type with some other form of locking.
232-
In many cases, a type from [`std::sync::atomic`](https://doc.rust-lang.org/std/sync/atomic/) or a [`std::sync::Mutex`](https://doc.rust-lang.org/std/sync/struct.Mutex.html) will be sufficient.
230+
[`GILProtected`] was a PyO3 type that allowed mutable access to static data by leveraging the GIL to lock concurrent access from other threads.
231+
In free-threaded Python there is no GIL, so this type had to be replaced with alternative forms of locking.
232+
In many cases, a type from [`std::sync::atomic`](https://doc.rust-lang.org/std/sync/atomic/) or a [`std::sync::Mutex`](https://doc.rust-lang.org/std/sync/struct.Mutex.html) was sufficient.
233233

234234
Before:
235235

236-
```rust
237-
# #![allow(deprecated)]
236+
```rust,ignore
238237
# fn main() {
239238
# #[cfg(not(Py_GIL_DISABLED))] {
240239
# use pyo3::prelude::*;
@@ -254,7 +253,7 @@ Python::attach(|py| {
254253
# }}
255254
```
256255

257-
After:
256+
After (using a `Mutex`):
258257

259258
```rust
260259
# use pyo3::prelude::*;

guide/src/migration.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ It exposes the same API as `GILOnceCell`, so should be a drop-in replacement wit
295295

296296
Before:
297297

298-
```rust
299-
# #![allow(deprecated)]
298+
```rust,ignore
300299
# use pyo3::prelude::*;
301300
# use pyo3::sync::GILOnceCell;
302301
# use pyo3::types::PyType;
@@ -336,8 +335,7 @@ Prefer to use concurrency primitives which are compatible with free-threaded Pyt
336335

337336
Before:
338337

339-
```rust
340-
# #![allow(deprecated)]
338+
```rust,ignore
341339
# use pyo3::prelude::*;
342340
# fn main() {
343341
# #[cfg(not(Py_GIL_DISABLED))] {
@@ -523,8 +521,7 @@ impl ToPyObject for MyPyObjectWrapper {
523521

524522
After:
525523

526-
```rust,no_run
527-
# #![allow(deprecated)]
524+
```rust,ignore
528525
# use pyo3::prelude::*;
529526
# #[allow(dead_code)]
530527
# struct MyPyObjectWrapper(PyObject);

newsfragments/5740.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove all functionality deprecated in PyO3 0.25 and 0.26.

src/instance.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,15 +2288,6 @@ impl<T> std::fmt::Debug for Py<T> {
22882288
}
22892289
}
22902290

2291-
/// A commonly-used alias for `Py<PyAny>`.
2292-
///
2293-
/// This is an owned reference a Python object without any type information. This value can also be
2294-
/// safely sent between threads.
2295-
///
2296-
/// See the documentation for [`Py`](struct.Py.html).
2297-
#[deprecated(since = "0.26.0", note = "use `Py<PyAny>` instead")]
2298-
pub type PyObject = Py<PyAny>;
2299-
23002291
impl Py<PyAny> {
23012292
/// Downcast this `Py<PyAny>` to a concrete Python type or pyclass.
23022293
///

src/interpreter_lifecycle.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ pub(crate) fn initialize() {
1919
});
2020
}
2121

22-
/// See [Python::initialize]
23-
#[cfg(not(any(PyPy, GraalPy)))]
24-
#[inline]
25-
#[deprecated(note = "use `Python::initialize` instead", since = "0.26.0")]
26-
pub fn prepare_freethreaded_python() {
27-
initialize();
28-
}
29-
3022
/// Executes the provided closure with an embedded Python interpreter.
3123
///
3224
/// This function initializes the Python interpreter, executes the provided closure, and then

src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,9 @@ pub use crate::conversion::{FromPyObject, IntoPyObject, IntoPyObjectExt};
341341
pub use crate::err::{CastError, CastIntoError, PyErr, PyErrArguments, PyResult, ToPyErr};
342342
#[allow(deprecated)]
343343
pub use crate::err::{DowncastError, DowncastIntoError};
344-
#[allow(deprecated)]
345-
pub use crate::instance::PyObject;
346344
pub use crate::instance::{Borrowed, Bound, BoundObject, Py};
347345
#[cfg(not(any(PyPy, GraalPy)))]
348-
#[allow(deprecated)]
349-
pub use crate::interpreter_lifecycle::{
350-
prepare_freethreaded_python, with_embedded_python_interpreter,
351-
};
346+
pub use crate::interpreter_lifecycle::with_embedded_python_interpreter;
352347
pub use crate::marker::Python;
353348
pub use crate::pycell::{PyRef, PyRefMut};
354349
pub use crate::pyclass::{PyClass, PyClassGuard, PyClassGuardMut};

src/marker.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,6 @@ pub struct Python<'py>(PhantomData<&'py AttachGuard>, PhantomData<NotSend>);
357357
struct NotSend(PhantomData<*mut Python<'static>>);
358358

359359
impl Python<'_> {
360-
/// See [Python::attach]
361-
#[inline]
362-
#[track_caller]
363-
#[deprecated(note = "use `Python::attach` instead", since = "0.26.0")]
364-
pub fn with_gil<F, R>(f: F) -> R
365-
where
366-
F: for<'py> FnOnce(Python<'py>) -> R,
367-
{
368-
Self::attach(f)
369-
}
370-
371360
/// Acquires the global interpreter lock, allowing access to the Python interpreter. The
372361
/// provided closure `F` will be executed with the acquired `Python` marker token.
373362
///
@@ -483,20 +472,6 @@ impl Python<'_> {
483472
crate::interpreter_lifecycle::initialize();
484473
}
485474

486-
/// See [Python::attach_unchecked]
487-
/// # Safety
488-
///
489-
/// If [`Python::attach`] would succeed, it is safe to call this function.
490-
#[inline]
491-
#[track_caller]
492-
#[deprecated(note = "use `Python::attach_unchecked` instead", since = "0.26.0")]
493-
pub unsafe fn with_gil_unchecked<F, R>(f: F) -> R
494-
where
495-
F: for<'py> FnOnce(Python<'py>) -> R,
496-
{
497-
unsafe { Self::attach_unchecked(f) }
498-
}
499-
500475
/// Like [`Python::attach`] except Python interpreter state checking is skipped.
501476
///
502477
/// Normally when attaching to the Python interpreter, PyO3 checks that it is in
@@ -519,17 +494,6 @@ impl Python<'_> {
519494
}
520495

521496
impl<'py> Python<'py> {
522-
/// See [Python::detach]
523-
#[inline]
524-
#[deprecated(note = "use `Python::detach` instead", since = "0.26.0")]
525-
pub fn allow_threads<T, F>(self, f: F) -> T
526-
where
527-
F: Ungil + FnOnce() -> T,
528-
T: Ungil,
529-
{
530-
self.detach(f)
531-
}
532-
533497
/// Temporarily releases the GIL, thus allowing other Python threads to run. The GIL will be
534498
/// reacquired when `F`'s scope ends.
535499
///
@@ -806,15 +770,6 @@ impl<'py> Python<'py> {
806770
}
807771

808772
impl<'unbound> Python<'unbound> {
809-
/// Deprecated version of [`Python::assume_attached`]
810-
///
811-
/// # Safety
812-
/// See [`Python::assume_attached`]
813-
#[inline]
814-
#[deprecated(since = "0.26.0", note = "use `Python::assume_attached` instead")]
815-
pub unsafe fn assume_gil_acquired() -> Python<'unbound> {
816-
unsafe { Self::assume_attached() }
817-
}
818773
/// Unsafely creates a Python token with an unbounded lifetime.
819774
///
820775
/// Many of PyO3 APIs use [`Python<'_>`] as proof that the calling thread is attached to the

src/prelude.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
1111
pub use crate::conversion::{FromPyObject, FromPyObjectOwned, IntoPyObject};
1212
pub use crate::err::{PyErr, PyResult};
13-
#[allow(deprecated)]
14-
pub use crate::instance::PyObject;
1513
pub use crate::instance::{Borrowed, Bound, Py};
1614
pub use crate::marker::Python;
1715
pub use crate::pycell::{PyRef, PyRefMut};

0 commit comments

Comments
 (0)