Skip to content

Commit a454f6e

Browse files
authored
feature gate deprecated APIs for PyFloat and PyComplex (#4145)
1 parent 5534a7b commit a454f6e

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/conversions/num_complex.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ use std::os::raw::c_double;
104104

105105
impl PyComplex {
106106
/// Deprecated form of [`PyComplex::from_complex_bound`]
107-
#[cfg_attr(
108-
not(feature = "gil-refs"),
109-
deprecated(
110-
since = "0.21.0",
111-
note = "`PyComplex::from_complex` will be replaced by `PyComplex::from_complex_bound` in a future PyO3 version"
112-
)
107+
#[cfg(feature = "gil-refs")]
108+
#[deprecated(
109+
since = "0.21.0",
110+
note = "`PyComplex::from_complex` will be replaced by `PyComplex::from_complex_bound` in a future PyO3 version"
113111
)]
114112
pub fn from_complex<F: Into<c_double>>(py: Python<'_>, complex: Complex<F>) -> &PyComplex {
115113
Self::from_complex_bound(py, complex).into_gil_ref()

src/types/complex.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ pyobject_native_type!(
2020

2121
impl PyComplex {
2222
/// Deprecated form of [`PyComplex::from_doubles_bound`]
23-
#[cfg_attr(
24-
not(feature = "gil-refs"),
25-
deprecated(
26-
since = "0.21.0",
27-
note = "`PyComplex::from_doubles` will be replaced by `PyComplex::from_doubles_bound` in a future PyO3 version"
28-
)
23+
#[cfg(feature = "gil-refs")]
24+
#[deprecated(
25+
since = "0.21.0",
26+
note = "`PyComplex::from_doubles` will be replaced by `PyComplex::from_doubles_bound` in a future PyO3 version"
2927
)]
3028
pub fn from_doubles(py: Python<'_>, real: c_double, imag: c_double) -> &PyComplex {
3129
Self::from_doubles_bound(py, real, imag).into_gil_ref()

src/types/float.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ pyobject_native_type!(
2626
impl PyFloat {
2727
/// Deprecated form of [`PyFloat::new_bound`].
2828
#[inline]
29-
#[cfg_attr(
30-
not(feature = "gil-refs"),
31-
deprecated(
32-
since = "0.21.0",
33-
note = "`PyFloat::new` will be replaced by `PyFloat::new_bound` in a future PyO3 version"
34-
)
29+
#[cfg(feature = "gil-refs")]
30+
#[deprecated(
31+
since = "0.21.0",
32+
note = "`PyFloat::new` will be replaced by `PyFloat::new_bound` in a future PyO3 version"
3533
)]
3634
pub fn new(py: Python<'_>, val: f64) -> &'_ Self {
3735
Self::new_bound(py, val).into_gil_ref()
@@ -154,9 +152,11 @@ impl<'py> FromPyObject<'py> for f32 {
154152
}
155153

156154
#[cfg(test)]
157-
#[cfg_attr(not(feature = "gil-refs"), allow(deprecated))]
158155
mod tests {
159-
use crate::{types::PyFloat, Python, ToPyObject};
156+
use crate::{
157+
types::{PyFloat, PyFloatMethods},
158+
Python, ToPyObject,
159+
};
160160

161161
macro_rules! num_to_py_object_and_back (
162162
($func_name:ident, $t1:ty, $t2:ty) => (
@@ -184,7 +184,7 @@ mod tests {
184184

185185
Python::with_gil(|py| {
186186
let v = 1.23f64;
187-
let obj = PyFloat::new(py, 1.23);
187+
let obj = PyFloat::new_bound(py, 1.23);
188188
assert_approx_eq!(v, obj.value());
189189
});
190190
}

0 commit comments

Comments
 (0)