Skip to content

Commit

Permalink
Merge pull request #3603 from davidhewitt/0.19-deprecations
Browse files Browse the repository at this point in the history
remove all functionality deprecated in 0.19
  • Loading branch information
davidhewitt authored Nov 28, 2023
2 parents 53311a9 + 5c6d490 commit e62e6ca
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 189 deletions.
2 changes: 1 addition & 1 deletion guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ impl pyo3::impl_::pyclass::PyClassImpl for MyClass {

fn doc(py: Python<'_>) -> pyo3::PyResult<&'static ::std::ffi::CStr> {
use pyo3::impl_::pyclass::*;
static DOC: pyo3::once_cell::GILOnceCell<::std::borrow::Cow<'static, ::std::ffi::CStr>> = pyo3::once_cell::GILOnceCell::new();
static DOC: pyo3::sync::GILOnceCell<::std::borrow::Cow<'static, ::std::ffi::CStr>> = pyo3::sync::GILOnceCell::new();
DOC.get_or_try_init(py, || {
let collector = PyClassImplCollector::<Self>::new();
build_pyclass_doc(<MyClass as pyo3::PyTypeInfo>::NAME, "", None.or_else(|| collector.new_text_signature()))
Expand Down
1 change: 1 addition & 0 deletions newsfragments/3603.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove all functionality deprecated in PyO3 0.19.
2 changes: 0 additions & 2 deletions pyo3-macros-backend/src/deprecations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use proc_macro2::{Span, TokenStream};
use quote::{quote_spanned, ToTokens};

pub enum Deprecation {
PyClassTextSignature,
PyMethodsNewDeprecatedForm,
}

impl Deprecation {
fn ident(&self, span: Span) -> syn::Ident {
let string = match self {
Deprecation::PyClassTextSignature => "PYCLASS_TEXT_SIGNATURE",
Deprecation::PyMethodsNewDeprecatedForm => "PYMETHODS_NEW_DEPRECATED_FORM",
};
syn::Ident::new(string, span)
Expand Down
21 changes: 3 additions & 18 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::attributes::{
ModuleAttribute, NameAttribute, NameLitStr, RenameAllAttribute, TextSignatureAttribute,
TextSignatureAttributeValue,
};
use crate::deprecations::{Deprecation, Deprecations};
use crate::deprecations::Deprecations;
use crate::konst::{ConstAttributes, ConstSpec};
use crate::method::FnSpec;
use crate::pyimpl::{gen_py_const, PyClassMethodsType};
Expand Down Expand Up @@ -34,15 +34,13 @@ pub enum PyClassKind {
pub struct PyClassArgs {
pub class_kind: PyClassKind,
pub options: PyClassPyO3Options,
pub deprecations: Deprecations,
}

impl PyClassArgs {
fn parse(input: ParseStream<'_>, kind: PyClassKind) -> Result<Self> {
Ok(PyClassArgs {
class_kind: kind,
options: PyClassPyO3Options::parse(input)?,
deprecations: Deprecations::new(),
})
}

Expand Down Expand Up @@ -73,8 +71,6 @@ pub struct PyClassPyO3Options {
pub text_signature: Option<TextSignatureAttribute>,
pub unsendable: Option<kw::unsendable>,
pub weakref: Option<kw::weakref>,

pub deprecations: Deprecations,
}

enum PyClassPyO3Option {
Expand All @@ -91,7 +87,6 @@ enum PyClassPyO3Option {
Sequence(kw::sequence),
SetAll(kw::set_all),
Subclass(kw::subclass),
TextSignature(TextSignatureAttribute),
Unsendable(kw::unsendable),
Weakref(kw::weakref),
}
Expand Down Expand Up @@ -125,8 +120,6 @@ impl Parse for PyClassPyO3Option {
input.parse().map(PyClassPyO3Option::SetAll)
} else if lookahead.peek(attributes::kw::subclass) {
input.parse().map(PyClassPyO3Option::Subclass)
} else if lookahead.peek(attributes::kw::text_signature) {
input.parse().map(PyClassPyO3Option::TextSignature)
} else if lookahead.peek(attributes::kw::unsendable) {
input.parse().map(PyClassPyO3Option::Unsendable)
} else if lookahead.peek(attributes::kw::weakref) {
Expand Down Expand Up @@ -181,11 +174,6 @@ impl PyClassPyO3Options {
PyClassPyO3Option::Sequence(sequence) => set_option!(sequence),
PyClassPyO3Option::SetAll(set_all) => set_option!(set_all),
PyClassPyO3Option::Subclass(subclass) => set_option!(subclass),
PyClassPyO3Option::TextSignature(text_signature) => {
self.deprecations
.push(Deprecation::PyClassTextSignature, text_signature.span());
set_option!(text_signature)
}
PyClassPyO3Option::Unsendable(unsendable) => set_option!(unsendable),
PyClassPyO3Option::Weakref(weakref) => set_option!(weakref),
}
Expand Down Expand Up @@ -355,7 +343,7 @@ fn impl_class(
methods_type: PyClassMethodsType,
krate: syn::Path,
) -> syn::Result<TokenStream> {
let pytypeinfo_impl = impl_pytypeinfo(cls, args, Some(&args.options.deprecations));
let pytypeinfo_impl = impl_pytypeinfo(cls, args, None);

let py_class_impl = PyClassImplsBuilder::new(
cls,
Expand Down Expand Up @@ -989,8 +977,6 @@ impl<'a> PyClassImplsBuilder<'a> {
let default_slot_defs = self.default_slots.iter().map(|slot| &slot.slot_def);
let freelist_slots = self.freelist_slots();

let deprecations = &self.attr.deprecations;

let class_mutability = if self.attr.options.frozen.is_some() {
quote! {
ImmutableChild
Expand Down Expand Up @@ -1040,7 +1026,6 @@ impl<'a> PyClassImplsBuilder<'a> {
fn items_iter() -> _pyo3::impl_::pyclass::PyClassItemsIter {
use _pyo3::impl_::pyclass::*;
let collector = PyClassImplCollector::<Self>::new();
#deprecations;
static INTRINSIC_ITEMS: PyClassItems = PyClassItems {
methods: &[#(#default_method_defs),*],
slots: &[#(#default_slot_defs),* #(#freelist_slots),*],
Expand All @@ -1050,7 +1035,7 @@ impl<'a> PyClassImplsBuilder<'a> {

fn doc(py: _pyo3::Python<'_>) -> _pyo3::PyResult<&'static ::std::ffi::CStr> {
use _pyo3::impl_::pyclass::*;
static DOC: _pyo3::once_cell::GILOnceCell<::std::borrow::Cow<'static, ::std::ffi::CStr>> = _pyo3::once_cell::GILOnceCell::new();
static DOC: _pyo3::sync::GILOnceCell<::std::borrow::Cow<'static, ::std::ffi::CStr>> = _pyo3::sync::GILOnceCell::new();
DOC.get_or_try_init(py, || {
let collector = PyClassImplCollector::<Self>::new();
build_pyclass_doc(<#cls as _pyo3::PyTypeInfo>::NAME, #doc, #deprecated_text_signature.or_else(|| collector.new_text_signature()))
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/rust_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
//! ```
use crate::exceptions::PyValueError;
use crate::once_cell::GILOnceCell;
use crate::sync::GILOnceCell;
use crate::types::PyType;
use crate::{intern, FromPyObject, IntoPy, Py, PyAny, PyObject, PyResult, Python, ToPyObject};
use rust_decimal::Decimal;
Expand Down
4 changes: 1 addition & 3 deletions src/conversions/std/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ where
{
fn into_py(self, py: Python<'_>) -> PyObject {
unsafe {
#[allow(deprecated)] // we're not on edition 2021 yet
let elements = std::array::IntoIter::new(self);
let len = N as ffi::Py_ssize_t;

let ptr = ffi::PyList_New(len);
Expand All @@ -21,7 +19,7 @@ where
// - its Drop cleans up the list if user code panics.
let list: Py<PyAny> = Py::from_owned_ptr(py, ptr);

for (i, obj) in (0..len).zip(elements) {
for (i, obj) in (0..len).zip(self) {
let obj = obj.into_py(py).into_ptr();

#[cfg(not(Py_LIMITED_API))]
Expand Down
6 changes: 0 additions & 6 deletions src/impl_/deprecations.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
//! Symbols used to denote deprecated usages of PyO3's proc macros.
#[deprecated(
since = "0.19.0",
note = "put `text_signature` on `#[new]` instead of `#[pyclass]`"
)]
pub const PYCLASS_TEXT_SIGNATURE: () = ();

#[deprecated(since = "0.20.0", note = "use `#[new]` instead of `#[__new__]`")]
pub const PYMETHODS_NEW_DEPRECATED_FORM: () = ();
9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,6 @@ pub mod type_object;
pub mod types;
mod version;

#[doc(hidden)]
#[deprecated(since = "0.19.0", note = "Please use the `sync` module instead.")]
pub mod once_cell {
// FIXME: We want to deprecate these,
// but that does not yet work for re-exports,
// c.f. https://github.com/rust-lang/rust/issues/30827
pub use crate::sync::{GILOnceCell, Interned};
}

#[allow(unused_imports)] // with no features enabled this module has no public exports
pub use crate::conversions::*;

Expand Down
30 changes: 0 additions & 30 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,6 @@ impl PySequence {
}
}

/// Returns a fresh list based on the Sequence.
#[inline]
#[deprecated(since = "0.19.0", note = "renamed to .to_list()")]
pub fn list(&self) -> PyResult<&PyList> {
self.to_list()
}

/// Returns a fresh tuple based on the Sequence.
#[inline]
pub fn to_tuple(&self) -> PyResult<&PyTuple> {
Expand All @@ -248,13 +241,6 @@ impl PySequence {
}
}

/// Returns a fresh tuple based on the Sequence.
#[inline]
#[deprecated(since = "0.19.0", note = "renamed to .to_tuple()")]
pub fn tuple(&self) -> PyResult<&PyTuple> {
self.to_tuple()
}

/// Register a pyclass as a subclass of `collections.abc.Sequence` (from the Python standard
/// library). This is equvalent to `collections.abc.Sequence.register(T)` in Python.
/// This registration is required for a pyclass to be downcastable from `PyAny` to `PySequence`.
Expand Down Expand Up @@ -803,10 +789,6 @@ mod tests {
let ob = v.to_object(py);
let seq = ob.downcast::<PySequence>(py).unwrap();
assert!(seq.to_list().unwrap().eq(PyList::new(py, &v)).unwrap());
#[allow(deprecated)]
{
assert!(seq.list().is_ok());
}
});
}

Expand All @@ -821,10 +803,6 @@ mod tests {
.unwrap()
.eq(PyList::new(py, ["f", "o", "o"]))
.unwrap());
#[allow(deprecated)]
{
assert!(seq.list().is_ok());
}
});
}

Expand All @@ -839,10 +817,6 @@ mod tests {
.unwrap()
.eq(PyTuple::new(py, ["foo", "bar"]))
.unwrap());
#[allow(deprecated)]
{
assert!(seq.tuple().is_ok());
}
});
}

Expand All @@ -853,10 +827,6 @@ mod tests {
let ob = v.to_object(py);
let seq = ob.downcast::<PySequence>(py).unwrap();
assert!(seq.to_tuple().unwrap().eq(PyTuple::new(py, &v)).unwrap());
#[allow(deprecated)]
{
assert!(seq.tuple().is_ok());
}
});
}

Expand Down
108 changes: 0 additions & 108 deletions tests/test_text_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,111 +435,3 @@ fn test_raw_identifiers() {
);
});
}

#[allow(deprecated)]
mod deprecated {
use crate::py_assert;
use pyo3::prelude::*;

#[test]
#[cfg_attr(all(Py_LIMITED_API, not(Py_3_10)), ignore)]
fn class_with_docs_and_signature() {
/// docs line1
#[pyclass]
/// docs line2
#[pyo3(text_signature = "(a, b=None, *, c=42)")]
/// docs line3
struct MyClass {}

#[pymethods]
impl MyClass {
#[new]
#[pyo3(signature = (a, b=None, *, c=42))]
fn __new__(a: i32, b: Option<i32>, c: i32) -> Self {
let _ = (a, b, c);
Self {}
}
}

Python::with_gil(|py| {
let typeobj = py.get_type::<MyClass>();

py_assert!(
py,
typeobj,
"typeobj.__doc__ == 'docs line1\\ndocs line2\\ndocs line3'"
);
py_assert!(
py,
typeobj,
"typeobj.__text_signature__ == '(a, b=None, *, c=42)'"
);
});
}

#[test]
#[cfg_attr(all(Py_LIMITED_API, not(Py_3_10)), ignore)]
fn class_with_deprecated_text_signature() {
#[pyclass]
#[pyo3(text_signature = "(a, b=None, *, c=42)")]
struct MyClass {}

#[pymethods]
impl MyClass {
#[new]
#[pyo3(signature = (a, b=None, *, c=42))]
fn __new__(a: i32, b: Option<i32>, c: i32) -> Self {
let _ = (a, b, c);
Self {}
}
}

Python::with_gil(|py| {
let typeobj = py.get_type::<MyClass>();

py_assert!(
py,
typeobj,
"typeobj.__doc__ is None or typeobj.__doc__ == ''"
);
py_assert!(
py,
typeobj,
"typeobj.__text_signature__ == '(a, b=None, *, c=42)'"
);
});
}

#[test]
#[cfg_attr(all(Py_LIMITED_API, not(Py_3_10)), ignore)]
fn class_with_deprecated_text_signature_and_on_new() {
#[pyclass(text_signature = "(a, b=None, *, c=42)")]
struct MyClass {}

#[pymethods]
impl MyClass {
#[new]
#[pyo3(signature = (a, b=None, *, c=42), text_signature = "(NOT, THIS, ONE)")]
fn __new__(a: i32, b: Option<i32>, c: i32) -> Self {
let _ = (a, b, c);
Self {}
}
}

Python::with_gil(|py| {
let typeobj = py.get_type::<MyClass>();
py_assert!(
py,
typeobj,
"typeobj.__doc__ is None or typeobj.__doc__ == ''"
);
// Deprecated `#[pyclass(text_signature)]` attribute will be preferred
// for backwards-compatibility.
py_assert!(
py,
typeobj,
"typeobj.__text_signature__ == '(a, b=None, *, c=42)'"
);
});
}
}
1 change: 0 additions & 1 deletion tests/ui/deprecations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use pyo3::prelude::*;

#[pyclass]
#[pyo3(text_signature = "()")]
struct MyClass;

#[pymethods]
Expand Down
10 changes: 2 additions & 8 deletions tests/ui/deprecations.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
error: use of deprecated constant `pyo3::impl_::deprecations::PYMETHODS_NEW_DEPRECATED_FORM`: use `#[new]` instead of `#[__new__]`
--> tests/ui/deprecations.rs:11:7
--> tests/ui/deprecations.rs:10:7
|
11 | #[__new__]
10 | #[__new__]
| ^^^^^^^
|
note: the lint level is defined here
--> tests/ui/deprecations.rs:1:9
|
1 | #![deny(deprecated)]
| ^^^^^^^^^^

error: use of deprecated constant `pyo3::impl_::deprecations::PYCLASS_TEXT_SIGNATURE`: put `text_signature` on `#[new]` instead of `#[pyclass]`
--> tests/ui/deprecations.rs:6:8
|
6 | #[pyo3(text_signature = "()")]
| ^^^^^^^^^^^^^^
Loading

0 comments on commit e62e6ca

Please sign in to comment.