Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature gate deprecated APIs for PyFrozenSet #4118

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions src/types/frozenset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ impl<'py> PyFrozenSetBuilder<'py> {
}

/// Deprecated form of [`PyFrozenSetBuilder::finalize_bound`]
#[cfg_attr(
not(feature = "gil-refs"),
deprecated(
since = "0.21.0",
note = "`PyFrozenSetBuilder::finalize` will be replaced by `PyFrozenSetBuilder::finalize_bound` in a future PyO3 version"
)
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "`PyFrozenSetBuilder::finalize` will be replaced by `PyFrozenSetBuilder::finalize_bound` in a future PyO3 version"
)]
pub fn finalize(self) -> &'py PyFrozenSet {
self.finalize_bound().into_gil_ref()
Expand Down Expand Up @@ -78,12 +76,10 @@ pyobject_native_type_core!(
impl PyFrozenSet {
/// Deprecated form of [`PyFrozenSet::new_bound`].
#[inline]
#[cfg_attr(
not(feature = "gil-refs"),
deprecated(
since = "0.21.0",
note = "`PyFrozenSet::new` will be replaced by `PyFrozenSet::new_bound` in a future PyO3 version"
)
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "`PyFrozenSet::new` will be replaced by `PyFrozenSet::new_bound` in a future PyO3 version"
)]
pub fn new<'a, 'p, T: ToPyObject + 'a>(
py: Python<'p>,
Expand All @@ -104,12 +100,10 @@ impl PyFrozenSet {
}

/// Deprecated form of [`PyFrozenSet::empty_bound`].
#[cfg_attr(
not(feature = "gil-refs"),
deprecated(
since = "0.21.0",
note = "`PyFrozenSet::empty` will be replaced by `PyFrozenSet::empty_bound` in a future PyO3 version"
)
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "`PyFrozenSet::empty` will be replaced by `PyFrozenSet::empty_bound` in a future PyO3 version"
)]
pub fn empty(py: Python<'_>) -> PyResult<&'_ PyFrozenSet> {
Self::empty_bound(py).map(Bound::into_gil_ref)
Expand Down Expand Up @@ -324,25 +318,24 @@ pub(crate) fn new_from_iter<T: ToPyObject>(
}

#[cfg(test)]
#[cfg_attr(not(feature = "gil-refs"), allow(deprecated))]
mod tests {
use super::*;

#[test]
fn test_frozenset_new_and_len() {
Python::with_gil(|py| {
let set = PyFrozenSet::new(py, &[1]).unwrap();
let set = PyFrozenSet::new_bound(py, &[1]).unwrap();
assert_eq!(1, set.len());

let v = vec![1];
assert!(PyFrozenSet::new(py, &[v]).is_err());
assert!(PyFrozenSet::new_bound(py, &[v]).is_err());
});
}

#[test]
fn test_frozenset_empty() {
Python::with_gil(|py| {
let set = PyFrozenSet::empty(py).unwrap();
let set = PyFrozenSet::empty_bound(py).unwrap();
assert_eq!(0, set.len());
assert!(set.is_empty());
});
Expand All @@ -351,15 +344,15 @@ mod tests {
#[test]
fn test_frozenset_contains() {
Python::with_gil(|py| {
let set = PyFrozenSet::new(py, &[1]).unwrap();
let set = PyFrozenSet::new_bound(py, &[1]).unwrap();
assert!(set.contains(1).unwrap());
});
}

#[test]
fn test_frozenset_iter() {
Python::with_gil(|py| {
let set = PyFrozenSet::new(py, &[1]).unwrap();
let set = PyFrozenSet::new_bound(py, &[1]).unwrap();

for el in set {
assert_eq!(1i32, el.extract::<i32>().unwrap());
Expand All @@ -381,7 +374,7 @@ mod tests {
#[test]
fn test_frozenset_iter_size_hint() {
Python::with_gil(|py| {
let set = PyFrozenSet::new(py, &[1]).unwrap();
let set = PyFrozenSet::new_bound(py, &[1]).unwrap();
let mut iter = set.iter();

// Exact size
Expand Down
Loading