Skip to content

Commit

Permalink
feature gate deprecated APIs for PyFloat and PyComplex (#4145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed May 1, 2024
1 parent 5534a7b commit a454f6e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
10 changes: 4 additions & 6 deletions src/conversions/num_complex.rs
Expand Up @@ -104,12 +104,10 @@ use std::os::raw::c_double;

impl PyComplex {
/// Deprecated form of [`PyComplex::from_complex_bound`]
#[cfg_attr(
not(feature = "gil-refs"),
deprecated(
since = "0.21.0",
note = "`PyComplex::from_complex` will be replaced by `PyComplex::from_complex_bound` in a future PyO3 version"
)
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "`PyComplex::from_complex` will be replaced by `PyComplex::from_complex_bound` in a future PyO3 version"
)]
pub fn from_complex<F: Into<c_double>>(py: Python<'_>, complex: Complex<F>) -> &PyComplex {
Self::from_complex_bound(py, complex).into_gil_ref()
Expand Down
10 changes: 4 additions & 6 deletions src/types/complex.rs
Expand Up @@ -20,12 +20,10 @@ pyobject_native_type!(

impl PyComplex {
/// Deprecated form of [`PyComplex::from_doubles_bound`]
#[cfg_attr(
not(feature = "gil-refs"),
deprecated(
since = "0.21.0",
note = "`PyComplex::from_doubles` will be replaced by `PyComplex::from_doubles_bound` in a future PyO3 version"
)
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "`PyComplex::from_doubles` will be replaced by `PyComplex::from_doubles_bound` in a future PyO3 version"
)]
pub fn from_doubles(py: Python<'_>, real: c_double, imag: c_double) -> &PyComplex {
Self::from_doubles_bound(py, real, imag).into_gil_ref()
Expand Down
18 changes: 9 additions & 9 deletions src/types/float.rs
Expand Up @@ -26,12 +26,10 @@ pyobject_native_type!(
impl PyFloat {
/// Deprecated form of [`PyFloat::new_bound`].
#[inline]
#[cfg_attr(
not(feature = "gil-refs"),
deprecated(
since = "0.21.0",
note = "`PyFloat::new` will be replaced by `PyFloat::new_bound` in a future PyO3 version"
)
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "`PyFloat::new` will be replaced by `PyFloat::new_bound` in a future PyO3 version"
)]
pub fn new(py: Python<'_>, val: f64) -> &'_ Self {
Self::new_bound(py, val).into_gil_ref()
Expand Down Expand Up @@ -154,9 +152,11 @@ impl<'py> FromPyObject<'py> for f32 {
}

#[cfg(test)]
#[cfg_attr(not(feature = "gil-refs"), allow(deprecated))]
mod tests {
use crate::{types::PyFloat, Python, ToPyObject};
use crate::{
types::{PyFloat, PyFloatMethods},
Python, ToPyObject,
};

macro_rules! num_to_py_object_and_back (
($func_name:ident, $t1:ty, $t2:ty) => (
Expand Down Expand Up @@ -184,7 +184,7 @@ mod tests {

Python::with_gil(|py| {
let v = 1.23f64;
let obj = PyFloat::new(py, 1.23);
let obj = PyFloat::new_bound(py, 1.23);
assert_approx_eq!(v, obj.value());
});
}
Expand Down

0 comments on commit a454f6e

Please sign in to comment.