Skip to content

Commit d1a0c72

Browse files
authored
feature gate deprecated APIs for PyCFunction (#4154)
1 parent c08f6c7 commit d1a0c72

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/types/function.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
#[cfg(feature = "gil-refs")]
12
use crate::derive_utils::PyFunctionArguments;
23
use crate::ffi_ptr_ext::FfiPtrExt;
34
use crate::py_result_ext::PyResultExt;
45
use crate::types::capsule::PyCapsuleMethods;
56
use crate::types::module::PyModuleMethods;
7+
#[cfg(feature = "gil-refs")]
8+
use crate::PyNativeType;
69
use crate::{
710
ffi,
811
impl_::pymethods::{self, PyMethodDef, PyMethodDefDestructor},
912
types::{PyCapsule, PyDict, PyModule, PyString, PyTuple},
1013
};
11-
use crate::{Bound, IntoPy, Py, PyAny, PyNativeType, PyResult, Python};
14+
use crate::{Bound, IntoPy, Py, PyAny, PyResult, Python};
1215
use std::cell::UnsafeCell;
1316
use std::ffi::CStr;
1417

@@ -20,12 +23,10 @@ pyobject_native_type_core!(PyCFunction, pyobject_native_static_type_object!(ffi:
2023

2124
impl PyCFunction {
2225
/// Deprecated form of [`PyCFunction::new_with_keywords_bound`]
23-
#[cfg_attr(
24-
not(feature = "gil-refs"),
25-
deprecated(
26-
since = "0.21.0",
27-
note = "`PyCFunction::new_with_keywords` will be replaced by `PyCFunction::new_with_keywords_bound` in a future PyO3 version"
28-
)
26+
#[cfg(feature = "gil-refs")]
27+
#[deprecated(
28+
since = "0.21.0",
29+
note = "`PyCFunction::new_with_keywords` will be replaced by `PyCFunction::new_with_keywords_bound` in a future PyO3 version"
2930
)]
3031
pub fn new_with_keywords<'a>(
3132
fun: ffi::PyCFunctionWithKeywords,
@@ -66,12 +67,10 @@ impl PyCFunction {
6667
}
6768

6869
/// Deprecated form of [`PyCFunction::new`]
69-
#[cfg_attr(
70-
not(feature = "gil-refs"),
71-
deprecated(
72-
since = "0.21.0",
73-
note = "`PyCFunction::new` will be replaced by `PyCFunction::new_bound` in a future PyO3 version"
74-
)
70+
#[cfg(feature = "gil-refs")]
71+
#[deprecated(
72+
since = "0.21.0",
73+
note = "`PyCFunction::new` will be replaced by `PyCFunction::new_bound` in a future PyO3 version"
7574
)]
7675
pub fn new<'a>(
7776
fun: ffi::PyCFunction,
@@ -104,12 +103,10 @@ impl PyCFunction {
104103
}
105104

106105
/// Deprecated form of [`PyCFunction::new_closure`]
107-
#[cfg_attr(
108-
not(feature = "gil-refs"),
109-
deprecated(
110-
since = "0.21.0",
111-
note = "`PyCFunction::new_closure` will be replaced by `PyCFunction::new_closure_bound` in a future PyO3 version"
112-
)
106+
#[cfg(feature = "gil-refs")]
107+
#[deprecated(
108+
since = "0.21.0",
109+
note = "`PyCFunction::new_closure` will be replaced by `PyCFunction::new_closure_bound` in a future PyO3 version"
113110
)]
114111
pub fn new_closure<'a, F, R>(
115112
py: Python<'a>,

0 commit comments

Comments
 (0)