From e4268d85916e4fd808aaf3cb4cdff3c0692de324 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:36:35 +0200 Subject: [PATCH 1/8] remove rustc-check-cfg check --- pyo3-build-config/src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pyo3-build-config/src/lib.rs b/pyo3-build-config/src/lib.rs index 4e705d2ca02..65d7f1bade4 100644 --- a/pyo3-build-config/src/lib.rs +++ b/pyo3-build-config/src/lib.rs @@ -257,11 +257,6 @@ pub fn print_feature_cfgs() { /// - #[doc(hidden)] pub fn print_expected_cfgs() { - if rustc_minor_version().is_some_and(|version| version < 80) { - // rustc 1.80.0 stabilized `rustc-check-cfg` feature, don't emit before - return; - } - println!("cargo:rustc-check-cfg=cfg(Py_LIMITED_API)"); println!("cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)"); println!("cargo:rustc-check-cfg=cfg(PyPy)"); From a785b21dbb6229c07d85a57c87c2a86dce17723d Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:46:21 +0200 Subject: [PATCH 2/8] simplify cfg'd diagnostic attribute --- src/impl_/pyclass.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index d195050906e..143a167d034 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -1060,23 +1060,17 @@ impl PyClassThreadChecker for ThreadCheckerImpl { } /// Trait denoting that this class is suitable to be used as a base type for PyClass. +#[diagnostic::on_unimplemented( + message = "pyclass `{Self}` cannot be subclassed", + label = "required for `#[pyclass(extends={Self})]`", + note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing" +)] #[cfg_attr( Py_LIMITED_API, diagnostic::on_unimplemented( - message = "pyclass `{Self}` cannot be subclassed", - label = "required for `#[pyclass(extends={Self})]`", - note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing", note = "with the `abi3` feature enabled, PyO3 does not support subclassing native types", ) )] -#[cfg_attr( - not(Py_LIMITED_API), - diagnostic::on_unimplemented( - message = "pyclass `{Self}` cannot be subclassed", - label = "required for `#[pyclass(extends={Self})]`", - note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing", - ) -)] pub trait PyClassBaseType: Sized { type LayoutAsBase: PyClassObjectBaseLayout; type BaseNativeType; From 2d9a377f6781a279ec76bed8ac0a27d809a2ba9e Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 13 Apr 2026 20:14:47 +0200 Subject: [PATCH 3/8] Fix pyproto comment --- src/impl_/callback.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl_/callback.rs b/src/impl_/callback.rs index 268c6cf2b8a..cb2ec012338 100644 --- a/src/impl_/callback.rs +++ b/src/impl_/callback.rs @@ -131,7 +131,7 @@ impl IntoPyCallbackOutput<'_, ffi::Py_ssize_t> for usize { } } -// Converters needed for `#[pyproto]` implementations +// Conversion traits needed by pyo3's macros impl IntoPyCallbackOutput<'_, bool> for bool { #[inline] From 8576ce01c6b824d105a12d853e49196f4c7ac68d Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 13 Apr 2026 21:25:38 +0200 Subject: [PATCH 4/8] Use poll_fn --- src/coroutine/cancel.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/coroutine/cancel.rs b/src/coroutine/cancel.rs index 49185fa56d7..2368753755e 100644 --- a/src/coroutine/cancel.rs +++ b/src/coroutine/cancel.rs @@ -1,6 +1,5 @@ use crate::{Py, PyAny}; -use std::future::Future; -use std::pin::Pin; +use std::future::poll_fn; use std::sync::{Arc, Mutex}; use std::task::{Context, Poll, Waker}; @@ -44,7 +43,7 @@ impl CancelHandle { /// Retrieve the exception thrown in the associated coroutine. pub async fn cancelled(&mut self) -> Py { - Cancelled(self).await + poll_fn(|cx| self.poll_cancelled(cx)).await } #[doc(hidden)] @@ -53,16 +52,6 @@ impl CancelHandle { } } -// Because `poll_fn` is not available in MSRV -struct Cancelled<'a>(&'a mut CancelHandle); - -impl Future for Cancelled<'_> { - type Output = Py; - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.0.poll_cancelled(cx) - } -} - #[doc(hidden)] pub struct ThrowCallback(Arc>); From 3cd71fac1da8509cc8c08cd26cf7efabd711ad01 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 13 Apr 2026 21:34:16 +0200 Subject: [PATCH 5/8] remove unused doc imports --- src/lib.rs | 1 - src/marker.rs | 3 --- src/types/iterator.rs | 1 - src/types/mod.rs | 1 - src/types/module.rs | 1 - src/types/weakref/proxy.rs | 1 - src/types/weakref/reference.rs | 1 - 7 files changed, 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b0e67e9b89d..50692aa4af7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -249,7 +249,6 @@ //! ```rust //! use pyo3::prelude::*; //! use pyo3::types::IntoPyDict; -//! use pyo3::ffi::c_str; //! //! fn main() -> PyResult<()> { //! Python::attach(|py| { diff --git a/src/marker.rs b/src/marker.rs index 4ecb9101685..5599a67128e 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -393,7 +393,6 @@ impl Python<'_> { /// /// ``` /// use pyo3::prelude::*; - /// use pyo3::ffi::c_str; /// /// # fn main() -> PyResult<()> { /// Python::attach(|py| -> PyResult<()> { @@ -581,7 +580,6 @@ impl<'py> Python<'py> { /// /// ``` /// # use pyo3::prelude::*; - /// # use pyo3::ffi::c_str; /// # Python::attach(|py| { /// let result = py.eval(c"[i * 10 for i in range(5)]", None, None).unwrap(); /// let res: Vec = result.extract().unwrap(); @@ -611,7 +609,6 @@ impl<'py> Python<'py> { /// use pyo3::{ /// prelude::*, /// types::{PyBytes, PyDict}, - /// ffi::c_str, /// }; /// Python::attach(|py| { /// let locals = PyDict::new(py); diff --git a/src/types/iterator.rs b/src/types/iterator.rs index b270e86fa74..f366d7b5c63 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -15,7 +15,6 @@ use crate::{ffi, Bound, Py, PyAny, PyErr, PyResult}; /// /// ```rust /// use pyo3::prelude::*; -/// use pyo3::ffi::c_str; /// /// # fn main() -> PyResult<()> { /// Python::attach(|py| -> PyResult<()> { diff --git a/src/types/mod.rs b/src/types/mod.rs index 6e25b230f3a..1e43c6cff65 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -60,7 +60,6 @@ pub use self::weakref::{PyWeakref, PyWeakrefMethods, PyWeakrefProxy, PyWeakrefRe /// ```rust /// use pyo3::prelude::*; /// use pyo3::types::PyDict; -/// use pyo3::ffi::c_str; /// /// # pub fn main() -> PyResult<()> { /// Python::attach(|py| { diff --git a/src/types/module.rs b/src/types/module.rs index 795ec737eeb..50bac28c9a6 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -142,7 +142,6 @@ impl PyModule { /// /// ```rust /// use pyo3::prelude::*; - /// use pyo3::ffi::c_str; /// use std::ffi::CString; /// /// # fn main() -> PyResult<()> { diff --git a/src/types/weakref/proxy.rs b/src/types/weakref/proxy.rs index 8271a1c7531..b5f99e4a045 100644 --- a/src/types/weakref/proxy.rs +++ b/src/types/weakref/proxy.rs @@ -108,7 +108,6 @@ impl PyWeakrefProxy { )] /// use pyo3::prelude::*; /// use pyo3::types::PyWeakrefProxy; - /// use pyo3::ffi::c_str; /// /// #[pyclass(weakref)] /// struct Foo { /* fields omitted */ } diff --git a/src/types/weakref/reference.rs b/src/types/weakref/reference.rs index e302eadea2e..89b87b1a5ae 100644 --- a/src/types/weakref/reference.rs +++ b/src/types/weakref/reference.rs @@ -115,7 +115,6 @@ impl PyWeakrefReference { )] /// use pyo3::prelude::*; /// use pyo3::types::PyWeakrefReference; - /// use pyo3::ffi::c_str; /// /// #[pyclass(weakref)] /// struct Foo { /* fields omitted */ } From 686f2401a799fd84552dcff7c727b8176a0db2e0 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 14 Apr 2026 12:36:25 +0200 Subject: [PATCH 6/8] Only emit note on < 3.12 --- src/impl_/pyclass.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index 143a167d034..114cc73a2dc 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -1066,9 +1066,9 @@ impl PyClassThreadChecker for ThreadCheckerImpl { note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing" )] #[cfg_attr( - Py_LIMITED_API, + all(Py_LIMITED_API, not(Py_3_12)), diagnostic::on_unimplemented( - note = "with the `abi3` feature enabled, PyO3 does not support subclassing native types", + note = "subclassing native types requires Python >= 3.12 when using the `abi3` feature", ) )] pub trait PyClassBaseType: Sized { From 3f5d02d7750147c1fb8e7bf3e4770ff3019a3da3 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 14 Apr 2026 13:35:12 +0200 Subject: [PATCH 7/8] Fix ui test --- tests/ui/abi3_nativetype_inheritance.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/abi3_nativetype_inheritance.stderr b/tests/ui/abi3_nativetype_inheritance.stderr index 3e9e4544467..c42e6aa0662 100644 --- a/tests/ui/abi3_nativetype_inheritance.stderr +++ b/tests/ui/abi3_nativetype_inheritance.stderr @@ -6,7 +6,7 @@ error[E0277]: pyclass `PyDict` cannot be subclassed | = help: the trait `PyClassBaseType` is not implemented for `PyDict` = note: `PyDict` must have `#[pyclass(subclass)]` to be eligible for subclassing - = note: with the `abi3` feature enabled, PyO3 does not support subclassing native types + = note: subclassing native types requires Python >= 3.12 when using the `abi3` feature help: the trait `PyClassBaseType` is implemented for `PyAny` --> src/types/any.rs | @@ -22,7 +22,7 @@ error[E0277]: pyclass `PyDict` cannot be subclassed | = help: the trait `PyClassBaseType` is not implemented for `PyDict` = note: `PyDict` must have `#[pyclass(subclass)]` to be eligible for subclassing - = note: with the `abi3` feature enabled, PyO3 does not support subclassing native types + = note: subclassing native types requires Python >= 3.12 when using the `abi3` feature help: the trait `PyClassBaseType` is implemented for `PyAny` --> src/types/any.rs | From 33a253e61babd25634cd37a590b12f22342394ce Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 14 Apr 2026 15:43:12 +0200 Subject: [PATCH 8/8] Eanble abi3_inheritance test again --- tests/test_compile_error.rs | 2 +- tests/ui/abi3_inheritance.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 1bca1d15371..e5b646239d7 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -79,7 +79,7 @@ fn test_compile_errors() { t.pass("tests/ui/pymodule_missing_docs.rs"); #[cfg(not(any(Py_LIMITED_API, feature = "experimental-inspect")))] t.pass("tests/ui/forbid_unsafe.rs"); - #[cfg(all(Py_LIMITED_API, not(Py_3_12), not(feature = "experimental-async")))] + #[cfg(all(Py_LIMITED_API, not(Py_3_12), feature = "experimental-async"))] // output changes with async feature t.compile_fail("tests/ui/abi3_inheritance.rs"); #[cfg(all(Py_LIMITED_API, not(Py_3_9)))] diff --git a/tests/ui/abi3_inheritance.stderr b/tests/ui/abi3_inheritance.stderr index f3b2e3a8fc2..a98a2b6148e 100644 --- a/tests/ui/abi3_inheritance.stderr +++ b/tests/ui/abi3_inheritance.stderr @@ -6,7 +6,7 @@ error[E0277]: pyclass `PyException` cannot be subclassed | = help: the trait `PyClassBaseType` is not implemented for `PyException` = note: `PyException` must have `#[pyclass(subclass)]` to be eligible for subclassing - = note: with the `abi3` feature enabled, PyO3 does not support subclassing native types + = note: subclassing native types requires Python >= 3.12 when using the `abi3` feature help: the trait `PyClassBaseType` is implemented for `PyAny` --> src/types/any.rs | @@ -22,7 +22,7 @@ error[E0277]: pyclass `PyException` cannot be subclassed | = help: the trait `PyClassBaseType` is not implemented for `PyException` = note: `PyException` must have `#[pyclass(subclass)]` to be eligible for subclassing - = note: with the `abi3` feature enabled, PyO3 does not support subclassing native types + = note: subclassing native types requires Python >= 3.12 when using the `abi3` feature help: the trait `PyClassBaseType` is implemented for `PyAny` --> src/types/any.rs |