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)"); 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>); 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] diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index d195050906e..114cc73a2dc 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -1060,21 +1060,15 @@ impl PyClassThreadChecker for ThreadCheckerImpl { } /// Trait denoting that this class is suitable to be used as a base type for PyClass. -#[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", - ) +#[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( - not(Py_LIMITED_API), + all(Py_LIMITED_API, not(Py_3_12)), 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 = "subclassing native types requires Python >= 3.12 when using the `abi3` feature", ) )] pub trait PyClassBaseType: Sized { 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 */ } 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 | 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 |