From d5e99b635da0669ed04f680d233d277ad79732ee Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 14 Jul 2022 23:03:46 +0100 Subject: [PATCH] refactor: remove all 0.15 deprecations --- CHANGELOG.md | 4 ++++ pyo3-macros-backend/src/deprecations.rs | 2 -- pyo3-macros-backend/src/method.rs | 14 +++---------- src/impl_/deprecations.rs | 3 --- src/lib.rs | 12 ----------- src/types/tuple.rs | 28 ------------------------- tests/test_compile_error.rs | 2 +- tests/test_proto_methods.rs | 26 ----------------------- tests/ui/deprecations.rs | 9 -------- tests/ui/deprecations.stderr | 26 +++++++++-------------- 10 files changed, 18 insertions(+), 108 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba768cb0..fa224c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added missing `warn_default_encoding` field to `PyConfig` on 3.10+. The previously missing field could result in incorrect behavior or crashes. [#2370](https://github.com/PyO3/pyo3/pull/2370) - Fixed order of `pathconfig_warnings` and `program_name` fields of `PyConfig` on 3.10+. Previously, the order of the fields was swapped and this could lead to incorrect behavior or crashes. [#2370](https://github.com/PyO3/pyo3/pull/2370) +### Removed + +- Remove all functionality deprecated in PyO3 0.15. [#2283](https://github.com/PyO3/pyo3/pull/2283) + ## [0.16.4] - 2022-04-14 ### Added diff --git a/pyo3-macros-backend/src/deprecations.rs b/pyo3-macros-backend/src/deprecations.rs index 755e8664..198b1635 100644 --- a/pyo3-macros-backend/src/deprecations.rs +++ b/pyo3-macros-backend/src/deprecations.rs @@ -2,14 +2,12 @@ use proc_macro2::{Span, TokenStream}; use quote::{quote_spanned, ToTokens}; pub enum Deprecation { - CallAttribute, PyClassGcOption, } impl Deprecation { fn ident(&self, span: Span) -> syn::Ident { let string = match self { - Deprecation::CallAttribute => "CALL_ATTRIBUTE", Deprecation::PyClassGcOption => "PYCLASS_GC_OPTION", }; syn::Ident::new(string, span) diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index ee8e193b..cbb477d1 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -3,7 +3,6 @@ use std::borrow::Cow; use crate::attributes::TextSignatureAttribute; -use crate::deprecations::Deprecation; use crate::params::{accept_args_kwargs, impl_arg_params}; use crate::pyfunction::PyFunctionOptions; use crate::pyfunction::{PyFunctionArgPyO3Attributes, PyFunctionSignature}; @@ -266,7 +265,6 @@ impl<'a> FnSpec<'a> { let PyFunctionOptions { text_signature, name, - mut deprecations, .. } = options; @@ -274,7 +272,7 @@ impl<'a> FnSpec<'a> { ty: fn_type_attr, args: fn_attrs, mut python_name, - } = parse_method_attributes(meth_attrs, name.map(|name| name.value.0), &mut deprecations)?; + } = parse_method_attributes(meth_attrs, name.map(|name| name.value.0))?; let (fn_type, skip_first_arg, fixed_convention) = Self::parse_fn_type(sig, fn_type_attr, &mut python_name)?; @@ -316,7 +314,7 @@ impl<'a> FnSpec<'a> { args: arguments, output: ty, doc, - deprecations, + deprecations: Deprecations::new(), text_signature, unsafety: sig.unsafety, }) @@ -609,7 +607,6 @@ struct MethodAttributes { fn parse_method_attributes( attrs: &mut Vec, mut python_name: Option, - deprecations: &mut Deprecations, ) -> Result { let mut new_attrs = Vec::new(); let mut args = Vec::new(); @@ -632,12 +629,7 @@ fn parse_method_attributes( } else if name.is_ident("init") || name.is_ident("__init__") { bail_spanned!(name.span() => "#[init] is disabled since PyO3 0.9.0"); } else if name.is_ident("call") || name.is_ident("__call__") { - deprecations.push(Deprecation::CallAttribute, name.span()); - ensure_spanned!( - python_name.is_none(), - python_name.span() => "`name` may not be used with `#[call]`" - ); - python_name = Some(syn::Ident::new("__call__", Span::call_site())); + bail_spanned!(name.span() => "use `fn __call__` instead of `#[call]` attribute since PyO3 0.17.0"); } else if name.is_ident("classmethod") { set_ty!(MethodTypeAttribute::ClassMethod, name); } else if name.is_ident("staticmethod") { diff --git a/src/impl_/deprecations.rs b/src/impl_/deprecations.rs index 72c8ff99..a80a6a96 100644 --- a/src/impl_/deprecations.rs +++ b/src/impl_/deprecations.rs @@ -1,8 +1,5 @@ //! Symbols used to denote deprecated usages of PyO3's proc macros. -#[deprecated(since = "0.15.0", note = "use `fn __call__` instead of `#[call]`")] -pub const CALL_ATTRIBUTE: () = (); - #[deprecated( since = "0.16.0", note = "implement a `__traverse__` `#[pymethod]` instead of using `gc` option" diff --git a/src/lib.rs b/src/lib.rs index ca87bf2c..13471c9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -390,18 +390,6 @@ mod version; pub use crate::conversions::*; -#[doc(hidden)] -#[deprecated( - since = "0.15.0", - note = "please import this with `use pyo3::...` or from the prelude instead" -)] -#[cfg(feature = "macros")] -pub mod proc_macro { - #[cfg(feature = "pyproto")] - pub use pyo3_macros::pyproto; - pub use pyo3_macros::{pyclass, pyfunction, pymethods, pymodule}; -} - #[cfg(all(feature = "macros", feature = "pyproto"))] pub use pyo3_macros::pyproto; #[cfg(feature = "macros")] diff --git a/src/types/tuple.rs b/src/types/tuple.rs index c816a71a..b198da72 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -136,34 +136,6 @@ impl PyTuple { } } - #[deprecated(since = "0.15.0", note = "use self.get_slice instead")] - /// Takes the slice `self[low:high]` and returns it as a new tuple. - /// - /// Indices must be nonnegative, and out-of-range indices are clipped to - /// `self.len()`. - pub fn slice(&self, low: isize, high: isize) -> &PyTuple { - unsafe { - self.py() - .from_owned_ptr(ffi::PyTuple_GetSlice(self.as_ptr(), low, high)) - } - } - - #[deprecated( - since = "0.15.0", - note = "use tuple.get_slice(low, tuple.len()) instead" - )] - /// Takes a slice of the tuple from `low` to the end and returns it as a new tuple. - pub fn split_from(&self, low: usize) -> &PyTuple { - unsafe { - let ptr = ffi::PyTuple_GetSlice( - self.as_ptr(), - get_ssize_index(low), - self.len() as Py_ssize_t, - ); - self.py().from_owned_ptr(ptr) - } - } - /// Gets the tuple item at the specified index. /// # Example /// ``` diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 6e34e184..181fcefb 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -1,6 +1,6 @@ #![cfg(feature = "macros")] -#[rustversion::stable] +#[rustversion::not(nightly)] #[cfg(not(target_arch = "wasm32"))] // Not possible to invoke compiler from wasm #[test] fn test_compile_errors() { diff --git a/tests/test_proto_methods.rs b/tests/test_proto_methods.rs index 635412ca..3724c4f9 100644 --- a/tests/test_proto_methods.rs +++ b/tests/test_proto_methods.rs @@ -417,32 +417,6 @@ fn callable() { py_assert!(py, nc, "not callable(nc)"); } -#[allow(deprecated)] -mod deprecated { - use super::*; - - #[pyclass] - struct Callable; - - #[pymethods] - impl Callable { - #[__call__] - fn __call__(&self, arg: i32) -> i32 { - arg * 6 - } - } - - #[test] - fn callable() { - let gil = Python::acquire_gil(); - let py = gil.python(); - - let c = Py::new(py, Callable).unwrap(); - py_assert!(py, c, "callable(c)"); - py_assert!(py, c, "c(7) == 42"); - } -} - #[pyclass] #[derive(Debug)] struct SetItem { diff --git a/tests/ui/deprecations.rs b/tests/ui/deprecations.rs index 7ad3f98e..74b3c630 100644 --- a/tests/ui/deprecations.rs +++ b/tests/ui/deprecations.rs @@ -2,15 +2,6 @@ use pyo3::prelude::*; -#[pyclass] -struct DeprecatedCall; - -#[pymethods] -impl DeprecatedCall { - #[call] - fn deprecated_call(&self) {} -} - #[pyclass(gc)] struct DeprecatedGc; diff --git a/tests/ui/deprecations.stderr b/tests/ui/deprecations.stderr index c5d6aba3..472e656e 100644 --- a/tests/ui/deprecations.stderr +++ b/tests/ui/deprecations.stderr @@ -1,17 +1,11 @@ -error: use of deprecated constant `pyo3::impl_::deprecations::CALL_ATTRIBUTE`: use `fn __call__` instead of `#[call]` - --> tests/ui/deprecations.rs:10:7 - | -10 | #[call] - | ^^^^ - | -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_GC_OPTION`: implement a `__traverse__` `#[pymethod]` instead of using `gc` option - --> tests/ui/deprecations.rs:14:11 - | -14 | #[pyclass(gc)] - | ^^ + --> tests/ui/deprecations.rs:5:11 + | +5 | #[pyclass(gc)] + | ^^ + | +note: the lint level is defined here + --> tests/ui/deprecations.rs:1:9 + | +1 | #![deny(deprecated)] + | ^^^^^^^^^^