Skip to content

Commit

Permalink
refactor: remove all 0.15 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jul 15, 2022
1 parent 379f29a commit d5e99b6
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 108 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 {
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)
Expand Down
14 changes: 3 additions & 11 deletions pyo3-macros-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -266,15 +265,14 @@ impl<'a> FnSpec<'a> {
let PyFunctionOptions {
text_signature,
name,
mut deprecations,
..
} = options;

let MethodAttributes {
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)?;
Expand Down Expand Up @@ -316,7 +314,7 @@ impl<'a> FnSpec<'a> {
args: arguments,
output: ty,
doc,
deprecations,
deprecations: Deprecations::new(),
text_signature,
unsafety: sig.unsafety,
})
Expand Down Expand Up @@ -609,7 +607,6 @@ struct MethodAttributes {
fn parse_method_attributes(
attrs: &mut Vec<syn::Attribute>,
mut python_name: Option<syn::Ident>,
deprecations: &mut Deprecations,
) -> Result<MethodAttributes> {
let mut new_attrs = Vec::new();
let mut args = Vec::new();
Expand All @@ -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") {
Expand Down
3 changes: 0 additions & 3 deletions src/impl_/deprecations.rs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 0 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
28 changes: 0 additions & 28 deletions src/types/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compile_error.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
26 changes: 0 additions & 26 deletions tests/test_proto_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions tests/ui/deprecations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

use pyo3::prelude::*;

#[pyclass]
struct DeprecatedCall;

#[pymethods]
impl DeprecatedCall {
#[call]
fn deprecated_call(&self) {}
}

#[pyclass(gc)]
struct DeprecatedGc;

Expand Down
26 changes: 10 additions & 16 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::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)]
| ^^^^^^^^^^

0 comments on commit d5e99b6

Please sign in to comment.