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
13 changes: 6 additions & 7 deletions guide/src/free-threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,15 @@ Python::attach(|py| {
});
```

### `GILProtected` is not exposed
### `GILProtected` has been removed

[`GILProtected`] is a (deprecated) PyO3 type that allows mutable access to static data by leveraging the GIL to lock concurrent access from other threads.
In free-threaded Python there is no GIL, so you will need to replace this type with some other form of locking.
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.
[`GILProtected`] was a PyO3 type that allowed mutable access to static data by leveraging the GIL to lock concurrent access from other threads.
In free-threaded Python there is no GIL, so this type had to be replaced with alternative forms of locking.
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.

Before:

```rust
# #![allow(deprecated)]
```rust,ignore
# fn main() {
# #[cfg(not(Py_GIL_DISABLED))] {
# use pyo3::prelude::*;
Expand All @@ -254,7 +253,7 @@ Python::attach(|py| {
# }}
```

After:
After (using a `Mutex`):

```rust
# use pyo3::prelude::*;
Expand Down
9 changes: 3 additions & 6 deletions guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ It exposes the same API as `GILOnceCell`, so should be a drop-in replacement wit

Before:

```rust
# #![allow(deprecated)]
```rust,ignore
# use pyo3::prelude::*;
# use pyo3::sync::GILOnceCell;
# use pyo3::types::PyType;
Expand Down Expand Up @@ -307,8 +306,7 @@ Prefer to use concurrency primitives which are compatible with free-threaded Pyt

Before:

```rust
# #![allow(deprecated)]
```rust,ignore
# use pyo3::prelude::*;
# fn main() {
# #[cfg(not(Py_GIL_DISABLED))] {
Expand Down Expand Up @@ -494,8 +492,7 @@ impl ToPyObject for MyPyObjectWrapper {

After:

```rust,no_run
# #![allow(deprecated)]
```rust,ignore
# use pyo3::prelude::*;
# #[allow(dead_code)]
# struct MyPyObjectWrapper(PyObject);
Expand Down
1 change: 1 addition & 0 deletions newsfragments/5740.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove all functionality deprecated in PyO3 0.25 and 0.26.
9 changes: 0 additions & 9 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2288,15 +2288,6 @@ impl<T> std::fmt::Debug for Py<T> {
}
}

/// A commonly-used alias for `Py<PyAny>`.
///
/// This is an owned reference a Python object without any type information. This value can also be
/// safely sent between threads.
///
/// See the documentation for [`Py`](struct.Py.html).
#[deprecated(since = "0.26.0", note = "use `Py<PyAny>` instead")]
pub type PyObject = Py<PyAny>;

impl Py<PyAny> {
/// Downcast this `Py<PyAny>` to a concrete Python type or pyclass.
///
Expand Down
8 changes: 0 additions & 8 deletions src/interpreter_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ pub(crate) fn initialize() {
});
}

/// See [Python::initialize]
#[cfg(not(any(PyPy, GraalPy)))]
#[inline]
#[deprecated(note = "use `Python::initialize` instead", since = "0.26.0")]
pub fn prepare_freethreaded_python() {
initialize();
}

/// Executes the provided closure with an embedded Python interpreter.
///
/// This function initializes the Python interpreter, executes the provided closure, and then
Expand Down
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,9 @@ pub use crate::conversion::{FromPyObject, IntoPyObject, IntoPyObjectExt};
pub use crate::err::{CastError, CastIntoError, PyErr, PyErrArguments, PyResult, ToPyErr};
#[allow(deprecated)]
pub use crate::err::{DowncastError, DowncastIntoError};
#[allow(deprecated)]
pub use crate::instance::PyObject;
pub use crate::instance::{Borrowed, Bound, BoundObject, Py};
#[cfg(not(any(PyPy, GraalPy)))]
#[allow(deprecated)]
pub use crate::interpreter_lifecycle::{
prepare_freethreaded_python, with_embedded_python_interpreter,
};
pub use crate::interpreter_lifecycle::with_embedded_python_interpreter;
pub use crate::marker::Python;
pub use crate::pycell::{PyRef, PyRefMut};
pub use crate::pyclass::{PyClass, PyClassGuard, PyClassGuardMut};
Expand Down
45 changes: 0 additions & 45 deletions src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,6 @@ pub struct Python<'py>(PhantomData<&'py AttachGuard>, PhantomData<NotSend>);
struct NotSend(PhantomData<*mut Python<'static>>);

impl Python<'_> {
/// See [Python::attach]
#[inline]
#[track_caller]
#[deprecated(note = "use `Python::attach` instead", since = "0.26.0")]
pub fn with_gil<F, R>(f: F) -> R
where
F: for<'py> FnOnce(Python<'py>) -> R,
{
Self::attach(f)
}

/// Acquires the global interpreter lock, allowing access to the Python interpreter. The
/// provided closure `F` will be executed with the acquired `Python` marker token.
///
Expand Down Expand Up @@ -483,20 +472,6 @@ impl Python<'_> {
crate::interpreter_lifecycle::initialize();
}

/// See [Python::attach_unchecked]
/// # Safety
///
/// If [`Python::attach`] would succeed, it is safe to call this function.
#[inline]
#[track_caller]
#[deprecated(note = "use `Python::attach_unchecked` instead", since = "0.26.0")]
pub unsafe fn with_gil_unchecked<F, R>(f: F) -> R
where
F: for<'py> FnOnce(Python<'py>) -> R,
{
unsafe { Self::attach_unchecked(f) }
}

/// Like [`Python::attach`] except Python interpreter state checking is skipped.
///
/// Normally when attaching to the Python interpreter, PyO3 checks that it is in
Expand All @@ -519,17 +494,6 @@ impl Python<'_> {
}

impl<'py> Python<'py> {
/// See [Python::detach]
#[inline]
#[deprecated(note = "use `Python::detach` instead", since = "0.26.0")]
pub fn allow_threads<T, F>(self, f: F) -> T
where
F: Ungil + FnOnce() -> T,
T: Ungil,
{
self.detach(f)
}

/// Temporarily releases the GIL, thus allowing other Python threads to run. The GIL will be
/// reacquired when `F`'s scope ends.
///
Expand Down Expand Up @@ -806,15 +770,6 @@ impl<'py> Python<'py> {
}

impl<'unbound> Python<'unbound> {
/// Deprecated version of [`Python::assume_attached`]
///
/// # Safety
/// See [`Python::assume_attached`]
#[inline]
#[deprecated(since = "0.26.0", note = "use `Python::assume_attached` instead")]
pub unsafe fn assume_gil_acquired() -> Python<'unbound> {
unsafe { Self::assume_attached() }
}
/// Unsafely creates a Python token with an unbounded lifetime.
///
/// Many of PyO3 APIs use [`Python<'_>`] as proof that the calling thread is attached to the
Expand Down
2 changes: 0 additions & 2 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

pub use crate::conversion::{FromPyObject, FromPyObjectOwned, IntoPyObject};
pub use crate::err::{PyErr, PyResult};
#[allow(deprecated)]
pub use crate::instance::PyObject;
pub use crate::instance::{Borrowed, Bound, Py};
pub use crate::marker::Python;
pub use crate::pycell::{PyRef, PyRefMut};
Expand Down
Loading
Loading