Skip to content

Commit d2f9e1e

Browse files
mejrsdavidhewitt
authored andcommitted
Misc cleanups (PyO3#5970)
* remove rustc-check-cfg check * simplify cfg'd diagnostic attribute * Fix pyproto comment * Use poll_fn * remove unused doc imports * Only emit note on < 3.12 * Fix ui test * Eanble abi3_inheritance test again
1 parent 44b1aa2 commit d2f9e1e

14 files changed

Lines changed: 14 additions & 45 deletions

File tree

pyo3-build-config/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ pub fn print_feature_cfgs() {
257257
/// - <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg>
258258
#[doc(hidden)]
259259
pub fn print_expected_cfgs() {
260-
if rustc_minor_version().is_some_and(|version| version < 80) {
261-
// rustc 1.80.0 stabilized `rustc-check-cfg` feature, don't emit before
262-
return;
263-
}
264-
265260
println!("cargo:rustc-check-cfg=cfg(Py_LIMITED_API)");
266261
println!("cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)");
267262
println!("cargo:rustc-check-cfg=cfg(PyPy)");

src/coroutine/cancel.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{Py, PyAny};
2-
use std::future::Future;
3-
use std::pin::Pin;
2+
use std::future::poll_fn;
43
use std::sync::{Arc, Mutex};
54
use std::task::{Context, Poll, Waker};
65

@@ -44,7 +43,7 @@ impl CancelHandle {
4443

4544
/// Retrieve the exception thrown in the associated coroutine.
4645
pub async fn cancelled(&mut self) -> Py<PyAny> {
47-
Cancelled(self).await
46+
poll_fn(|cx| self.poll_cancelled(cx)).await
4847
}
4948

5049
#[doc(hidden)]
@@ -53,16 +52,6 @@ impl CancelHandle {
5352
}
5453
}
5554

56-
// Because `poll_fn` is not available in MSRV
57-
struct Cancelled<'a>(&'a mut CancelHandle);
58-
59-
impl Future for Cancelled<'_> {
60-
type Output = Py<PyAny>;
61-
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
62-
self.0.poll_cancelled(cx)
63-
}
64-
}
65-
6655
#[doc(hidden)]
6756
pub struct ThrowCallback(Arc<Mutex<Inner>>);
6857

src/impl_/callback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl IntoPyCallbackOutput<'_, ffi::Py_ssize_t> for usize {
131131
}
132132
}
133133

134-
// Converters needed for `#[pyproto]` implementations
134+
// Conversion traits needed by pyo3's macros
135135

136136
impl IntoPyCallbackOutput<'_, bool> for bool {
137137
#[inline]

src/impl_/pyclass.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,21 +1060,15 @@ impl<T> PyClassThreadChecker<T> for ThreadCheckerImpl {
10601060
}
10611061

10621062
/// Trait denoting that this class is suitable to be used as a base type for PyClass.
1063-
#[cfg_attr(
1064-
Py_LIMITED_API,
1065-
diagnostic::on_unimplemented(
1066-
message = "pyclass `{Self}` cannot be subclassed",
1067-
label = "required for `#[pyclass(extends={Self})]`",
1068-
note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing",
1069-
note = "with the `abi3` feature enabled, PyO3 does not support subclassing native types",
1070-
)
1063+
#[diagnostic::on_unimplemented(
1064+
message = "pyclass `{Self}` cannot be subclassed",
1065+
label = "required for `#[pyclass(extends={Self})]`",
1066+
note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing"
10711067
)]
10721068
#[cfg_attr(
1073-
not(Py_LIMITED_API),
1069+
all(Py_LIMITED_API, not(Py_3_12)),
10741070
diagnostic::on_unimplemented(
1075-
message = "pyclass `{Self}` cannot be subclassed",
1076-
label = "required for `#[pyclass(extends={Self})]`",
1077-
note = "`{Self}` must have `#[pyclass(subclass)]` to be eligible for subclassing",
1071+
note = "subclassing native types requires Python >= 3.12 when using the `abi3` feature",
10781072
)
10791073
)]
10801074
pub trait PyClassBaseType: Sized {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@
249249
//! ```rust
250250
//! use pyo3::prelude::*;
251251
//! use pyo3::types::IntoPyDict;
252-
//! use pyo3::ffi::c_str;
253252
//!
254253
//! fn main() -> PyResult<()> {
255254
//! Python::attach(|py| {

src/marker.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ impl Python<'_> {
393393
///
394394
/// ```
395395
/// use pyo3::prelude::*;
396-
/// use pyo3::ffi::c_str;
397396
///
398397
/// # fn main() -> PyResult<()> {
399398
/// Python::attach(|py| -> PyResult<()> {
@@ -581,7 +580,6 @@ impl<'py> Python<'py> {
581580
///
582581
/// ```
583582
/// # use pyo3::prelude::*;
584-
/// # use pyo3::ffi::c_str;
585583
/// # Python::attach(|py| {
586584
/// let result = py.eval(c"[i * 10 for i in range(5)]", None, None).unwrap();
587585
/// let res: Vec<i64> = result.extract().unwrap();
@@ -611,7 +609,6 @@ impl<'py> Python<'py> {
611609
/// use pyo3::{
612610
/// prelude::*,
613611
/// types::{PyBytes, PyDict},
614-
/// ffi::c_str,
615612
/// };
616613
/// Python::attach(|py| {
617614
/// let locals = PyDict::new(py);

src/types/iterator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::{ffi, Bound, Py, PyAny, PyErr, PyResult};
1515
///
1616
/// ```rust
1717
/// use pyo3::prelude::*;
18-
/// use pyo3::ffi::c_str;
1918
///
2019
/// # fn main() -> PyResult<()> {
2120
/// Python::attach(|py| -> PyResult<()> {

src/types/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub use self::weakref::{PyWeakref, PyWeakrefMethods, PyWeakrefProxy, PyWeakrefRe
6060
/// ```rust
6161
/// use pyo3::prelude::*;
6262
/// use pyo3::types::PyDict;
63-
/// use pyo3::ffi::c_str;
6463
///
6564
/// # pub fn main() -> PyResult<()> {
6665
/// Python::attach(|py| {

src/types/module.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ impl PyModule {
142142
///
143143
/// ```rust
144144
/// use pyo3::prelude::*;
145-
/// use pyo3::ffi::c_str;
146145
/// use std::ffi::CString;
147146
///
148147
/// # fn main() -> PyResult<()> {

src/types/weakref/proxy.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ impl PyWeakrefProxy {
108108
)]
109109
/// use pyo3::prelude::*;
110110
/// use pyo3::types::PyWeakrefProxy;
111-
/// use pyo3::ffi::c_str;
112111
///
113112
/// #[pyclass(weakref)]
114113
/// struct Foo { /* fields omitted */ }

0 commit comments

Comments
 (0)