diff --git a/guide/src/class.md b/guide/src/class.md index 460fed6b34c..8772e857d7e 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -1410,13 +1410,6 @@ impl<'a, 'py> pyo3::impl_::extract_argument::PyFunctionArgument<'a, 'py, false> } } -#[allow(deprecated)] -impl pyo3::IntoPy for MyClass { - fn into_py(self, py: pyo3::Python<'_>) -> pyo3::PyObject { - pyo3::IntoPy::into_py(pyo3::Py::new(py, self).unwrap(), py) - } -} - impl pyo3::impl_::pyclass::PyClassImpl for MyClass { const IS_BASETYPE: bool = false; const IS_SUBCLASS: bool = false; diff --git a/guide/src/conversions/traits.md b/guide/src/conversions/traits.md index 4ffdf802a87..b1b6cd31127 100755 --- a/guide/src/conversions/traits.md +++ b/guide/src/conversions/traits.md @@ -738,55 +738,7 @@ let vec_of_pyobjs: Vec> = Python::with_gil(|py| { In the example above we used `BoundObject::into_any` and `BoundObject::unbind` to manipulate the python types and smart pointers into the result type we wanted to produce from the function. -### `IntoPy` - -
- -⚠️ Warning: API update in progress 🛠️ - -PyO3 0.23 has introduced `IntoPyObject` as the new trait for to-python conversions. While `#[pymethods]` and `#[pyfunction]` contain a compatibility layer to allow `IntoPy` as a return type, all Python API have been migrated to use `IntoPyObject`. To migrate implement `IntoPyObject` for your type. -
- - -This trait defines the to-python conversion for a Rust type. It is usually implemented as -`IntoPy`, which is the trait needed for returning a value from `#[pyfunction]` and -`#[pymethods]`. - -All types in PyO3 implement this trait, as does a `#[pyclass]` which doesn't use `extends`. - -Occasionally you may choose to implement this for custom types which are mapped to Python types -_without_ having a unique python type. - -```rust,no_run -use pyo3::prelude::*; -# #[allow(dead_code)] -struct MyPyObjectWrapper(PyObject); - -#[allow(deprecated)] -impl IntoPy for MyPyObjectWrapper { - fn into_py(self, py: Python<'_>) -> PyObject { - self.0 - } -} -``` - -### The `ToPyObject` trait - -
- -⚠️ Warning: API update in progress 🛠️ - -PyO3 0.23 has introduced `IntoPyObject` as the new trait for to-python conversions. To migrate -implement `IntoPyObject` on a reference of your type (`impl<'py> IntoPyObject<'py> for &Type { ... }`). -
- -[`ToPyObject`] is a conversion trait that allows various objects to be -converted into [`PyObject`]. `IntoPy` serves the -same purpose, except that it consumes `self`. - -[`IntoPy`]: {{#PYO3_DOCS_URL}}/pyo3/conversion/trait.IntoPy.html [`FromPyObject`]: {{#PYO3_DOCS_URL}}/pyo3/conversion/trait.FromPyObject.html -[`ToPyObject`]: {{#PYO3_DOCS_URL}}/pyo3/conversion/trait.ToPyObject.html [`IntoPyObject`]: {{#PYO3_DOCS_URL}}/pyo3/conversion/trait.IntoPyObject.html [`IntoPyObjectExt`]: {{#PYO3_DOCS_URL}}/pyo3/conversion/trait.IntoPyObjectExt.html [`PyObject`]: {{#PYO3_DOCS_URL}}/pyo3/type.PyObject.html diff --git a/guide/src/migration.md b/guide/src/migration.md index e421ff659ff..13ca506662c 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -1237,7 +1237,7 @@ Python::with_gil(|py| { After, some type annotations may be necessary: -```rust +```rust,ignore # #![allow(deprecated)] # use pyo3::prelude::*; # @@ -1712,7 +1712,7 @@ impl FromPy for PyObject { ``` After -```rust,no_run +```rust,ignore # use pyo3::prelude::*; # #[allow(dead_code)] struct MyPyObjectWrapper(PyObject); @@ -1736,7 +1736,7 @@ let obj = PyObject::from_py(1.234, py); ``` After: -```rust,no_run +```rust,ignore # #![allow(deprecated)] # use pyo3::prelude::*; # Python::with_gil(|py| { diff --git a/newsfragments/5010.removed.md b/newsfragments/5010.removed.md new file mode 100644 index 00000000000..9b42e682154 --- /dev/null +++ b/newsfragments/5010.removed.md @@ -0,0 +1 @@ +Remove deprecated `IntoPy` and `ToPyObject` traits \ No newline at end of file diff --git a/pyo3-benches/benches/bench_intopyobject.rs b/pyo3-benches/benches/bench_intopyobject.rs index 42af893cd8a..0e1fbad1a57 100644 --- a/pyo3-benches/benches/bench_intopyobject.rs +++ b/pyo3-benches/benches/bench_intopyobject.rs @@ -46,15 +46,6 @@ fn byte_slice_into_pyobject_large(b: &mut Bencher<'_>) { bench_bytes_into_pyobject(b, &data); } -#[allow(deprecated)] -fn byte_slice_into_py(b: &mut Bencher<'_>) { - Python::with_gil(|py| { - let data = (0..u8::MAX).collect::>(); - let bytes = data.as_slice(); - b.iter_with_large_drop(|| black_box(bytes).into_py(py)); - }); -} - fn vec_into_pyobject(b: &mut Bencher<'_>) { Python::with_gil(|py| { let bytes = (0..u8::MAX).collect::>(); @@ -62,14 +53,6 @@ fn vec_into_pyobject(b: &mut Bencher<'_>) { }); } -#[allow(deprecated)] -fn vec_into_py(b: &mut Bencher<'_>) { - Python::with_gil(|py| { - let bytes = (0..u8::MAX).collect::>(); - b.iter_with_large_drop(|| black_box(&bytes).clone().into_py(py)); - }); -} - fn criterion_benchmark(c: &mut Criterion) { c.bench_function("bytes_new_small", bytes_new_small); c.bench_function("bytes_new_medium", bytes_new_medium); @@ -86,9 +69,7 @@ fn criterion_benchmark(c: &mut Criterion) { "byte_slice_into_pyobject_large", byte_slice_into_pyobject_large, ); - c.bench_function("byte_slice_into_py", byte_slice_into_py); c.bench_function("vec_into_pyobject", vec_into_pyobject); - c.bench_function("vec_into_py", vec_into_py); } criterion_group!(benches, criterion_benchmark); diff --git a/pyo3-benches/benches/bench_tuple.rs b/pyo3-benches/benches/bench_tuple.rs index e235567e926..cba7573c9d2 100644 --- a/pyo3-benches/benches/bench_tuple.rs +++ b/pyo3-benches/benches/bench_tuple.rs @@ -115,13 +115,6 @@ fn tuple_to_list(b: &mut Bencher<'_>) { }); } -#[allow(deprecated)] -fn tuple_into_py(b: &mut Bencher<'_>) { - Python::with_gil(|py| { - b.iter(|| -> PyObject { (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).into_py(py) }); - }); -} - fn tuple_into_pyobject(b: &mut Bencher<'_>) { Python::with_gil(|py| { b.iter(|| { @@ -175,7 +168,6 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("sequence_from_tuple", sequence_from_tuple); c.bench_function("tuple_new_list", tuple_new_list); c.bench_function("tuple_to_list", tuple_to_list); - c.bench_function("tuple_into_py", tuple_into_py); c.bench_function("tuple_into_pyobject", tuple_into_pyobject); } diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index aadfe2332ad..b524f667a7a 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1029,35 +1029,6 @@ fn impl_complex_enum( ) .doc(doc); - // Need to customize the into_py impl so that it returns the variant PyClass - let enum_into_py_impl = { - let match_arms: Vec = variants - .iter() - .map(|variant| { - let variant_ident = variant.get_ident(); - let variant_cls = gen_complex_enum_variant_class_ident(cls, variant.get_ident()); - quote! { - #cls::#variant_ident { .. } => { - let pyclass_init = <#pyo3_path::PyClassInitializer as ::std::convert::From>::from(self).add_subclass(#variant_cls); - let variant_value = #pyo3_path::Py::new(py, pyclass_init).unwrap(); - #pyo3_path::IntoPy::into_py(variant_value, py) - } - } - }) - .collect(); - - quote! { - #[allow(deprecated)] - impl #pyo3_path::IntoPy<#pyo3_path::PyObject> for #cls { - fn into_py(self, py: #pyo3_path::Python) -> #pyo3_path::PyObject { - match self { - #(#match_arms)* - } - } - } - } - }; - let enum_into_pyobject_impl = { let match_arms = variants .iter() @@ -1093,7 +1064,6 @@ fn impl_complex_enum( let pyclass_impls: TokenStream = [ impl_builder.impl_pyclass(ctx), impl_builder.impl_extractext(ctx), - enum_into_py_impl, enum_into_pyobject_impl, impl_builder.impl_pyclassimpl(ctx)?, impl_builder.impl_add_to_module(ctx), @@ -2142,13 +2112,6 @@ impl<'a> PyClassImplsBuilder<'a> { // If #cls is not extended type, we allow Self->PyObject conversion if attr.options.extends.is_none() { quote! { - #[allow(deprecated)] - impl #pyo3_path::IntoPy<#pyo3_path::PyObject> for #cls { - fn into_py(self, py: #pyo3_path::Python<'_>) -> #pyo3_path::PyObject { - #pyo3_path::IntoPy::into_py(#pyo3_path::Py::new(py, self).unwrap(), py) - } - } - impl<'py> #pyo3_path::conversion::IntoPyObject<'py> for #cls { type Target = Self; type Output = #pyo3_path::Bound<'py, >::Target>; diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index a1689e4e75c..a6d692775ef 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -845,8 +845,6 @@ pub fn impl_py_getter_def( #ty, Offset, { #pyo3_path::impl_::pyclass::IsPyT::<#ty>::VALUE }, - { #pyo3_path::impl_::pyclass::IsToPyObject::<#ty>::VALUE }, - { #pyo3_path::impl_::pyclass::IsIntoPy::<#ty>::VALUE }, { #pyo3_path::impl_::pyclass::IsIntoPyObjectRef::<#ty>::VALUE }, { #pyo3_path::impl_::pyclass::IsIntoPyObject::<#ty>::VALUE }, > = unsafe { #pyo3_path::impl_::pyclass::PyClassGetterGenerator::new() }; diff --git a/src/conversion.rs b/src/conversion.rs index 073a1fde2e9..53c9f3a9de8 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -6,7 +6,7 @@ use crate::pyclass::boolean_struct::False; use crate::types::any::PyAnyMethods; use crate::types::PyTuple; use crate::{ - ffi, Borrowed, Bound, BoundObject, Py, PyAny, PyClass, PyErr, PyObject, PyRef, PyRefMut, Python, + ffi, Borrowed, Bound, BoundObject, Py, PyAny, PyClass, PyErr, PyRef, PyRefMut, Python, }; use std::convert::Infallible; @@ -66,116 +66,6 @@ pub unsafe trait AsPyPointer { fn as_ptr(&self) -> *mut ffi::PyObject; } -/// Conversion trait that allows various objects to be converted into `PyObject`. -#[deprecated( - since = "0.23.0", - note = "`ToPyObject` is going to be replaced by `IntoPyObject`. See the migration guide (https://pyo3.rs/v0.23.0/migration) for more information." -)] -pub trait ToPyObject { - /// Converts self into a Python object. - fn to_object(&self, py: Python<'_>) -> PyObject; -} - -/// Defines a conversion from a Rust type to a Python object. -/// -/// It functions similarly to std's [`Into`] trait, but requires a [GIL token](Python) -/// as an argument. Many functions and traits internal to PyO3 require this trait as a bound, -/// so a lack of this trait can manifest itself in different error messages. -/// -/// # Examples -/// ## With `#[pyclass]` -/// The easiest way to implement `IntoPy` is by exposing a struct as a native Python object -/// by annotating it with [`#[pyclass]`](crate::prelude::pyclass). -/// -/// ```rust,no_run -/// use pyo3::prelude::*; -/// -/// # #[allow(dead_code)] -/// #[pyclass] -/// struct Number { -/// #[pyo3(get, set)] -/// value: i32, -/// } -/// ``` -/// Python code will see this as an instance of the `Number` class with a `value` attribute. -/// -/// ## Conversion to a Python object -/// -/// However, it may not be desirable to expose the existence of `Number` to Python code. -/// `IntoPy` allows us to define a conversion to an appropriate Python object. -/// ```rust,no_run -/// #![allow(deprecated)] -/// use pyo3::prelude::*; -/// -/// # #[allow(dead_code)] -/// struct Number { -/// value: i32, -/// } -/// -/// impl IntoPy for Number { -/// fn into_py(self, py: Python<'_>) -> PyObject { -/// // delegates to i32's IntoPy implementation. -/// self.value.into_py(py) -/// } -/// } -/// ``` -/// Python code will see this as an `int` object. -/// -/// ## Dynamic conversion into Python objects. -/// It is also possible to return a different Python object depending on some condition. -/// This is useful for types like enums that can carry different types. -/// -/// ```rust -/// #![allow(deprecated)] -/// use pyo3::prelude::*; -/// -/// enum Value { -/// Integer(i32), -/// String(String), -/// None, -/// } -/// -/// impl IntoPy for Value { -/// fn into_py(self, py: Python<'_>) -> PyObject { -/// match self { -/// Self::Integer(val) => val.into_py(py), -/// Self::String(val) => val.into_py(py), -/// Self::None => py.None(), -/// } -/// } -/// } -/// # fn main() { -/// # Python::with_gil(|py| { -/// # let v = Value::Integer(73).into_py(py); -/// # let v = v.extract::(py).unwrap(); -/// # -/// # let v = Value::String("foo".into()).into_py(py); -/// # let v = v.extract::(py).unwrap(); -/// # -/// # let v = Value::None.into_py(py); -/// # let v = v.extract::>>(py).unwrap(); -/// # }); -/// # } -/// ``` -/// Python code will see this as any of the `int`, `string` or `None` objects. -#[cfg_attr( - diagnostic_namespace, - diagnostic::on_unimplemented( - message = "`{Self}` cannot be converted to a Python object", - note = "`IntoPy` is automatically implemented by the `#[pyclass]` macro", - note = "if you do not wish to have a corresponding Python type, implement it manually", - note = "if you do not own `{Self}` you can perform a manual conversion to one of the types in `pyo3::types::*`" - ) -)] -#[deprecated( - since = "0.23.0", - note = "`IntoPy` is going to be replaced by `IntoPyObject`. See the migration guide (https://pyo3.rs/v0.23.0/migration) for more information." -)] -pub trait IntoPy: Sized { - /// Performs the conversion. - fn into_py(self, py: Python<'_>) -> T; -} - /// Defines a conversion from a Rust type to a Python object, which may fail. /// /// This trait has `#[derive(IntoPyObject)]` to automatically implement it for simple types and @@ -541,16 +431,6 @@ where } } -/// Identity conversion: allows using existing `PyObject` instances where -/// `T: ToPyObject` is expected. -#[allow(deprecated)] -impl ToPyObject for &'_ T { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - ::to_object(*self, py) - } -} - impl FromPyObject<'_> for T where T: PyClass + Clone, @@ -579,14 +459,6 @@ where } } -/// Converts `()` to an empty Python tuple. -#[allow(deprecated)] -impl IntoPy> for () { - fn into_py(self, py: Python<'_>) -> Py { - PyTuple::empty(py).unbind() - } -} - impl<'py> IntoPyObject<'py> for () { type Target = PyTuple; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index 342ed659e22..6fd4465ca34 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -58,31 +58,13 @@ use crate::types::{ timezone_utc, PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTzInfo, PyTzInfoAccess, }; -use crate::{ffi, Bound, FromPyObject, IntoPyObjectExt, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{ffi, Bound, FromPyObject, IntoPyObjectExt, PyAny, PyErr, PyResult, Python}; use chrono::offset::{FixedOffset, Utc}; use chrono::{ DateTime, Datelike, Duration, LocalResult, NaiveDate, NaiveDateTime, NaiveTime, Offset, TimeZone, Timelike, }; -#[allow(deprecated)] -impl ToPyObject for Duration { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Duration { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for Duration { #[cfg(Py_LIMITED_API)] type Target = PyAny; @@ -174,22 +156,6 @@ impl FromPyObject<'_> for Duration { } } -#[allow(deprecated)] -impl ToPyObject for NaiveDate { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for NaiveDate { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for NaiveDate { #[cfg(Py_LIMITED_API)] type Target = PyAny; @@ -241,22 +207,6 @@ impl FromPyObject<'_> for NaiveDate { } } -#[allow(deprecated)] -impl ToPyObject for NaiveTime { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for NaiveTime { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for NaiveTime { #[cfg(Py_LIMITED_API)] type Target = PyAny; @@ -318,22 +268,6 @@ impl FromPyObject<'_> for NaiveTime { } } -#[allow(deprecated)] -impl ToPyObject for NaiveDateTime { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for NaiveDateTime { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for NaiveDateTime { #[cfg(Py_LIMITED_API)] type Target = PyAny; @@ -407,24 +341,6 @@ impl FromPyObject<'_> for NaiveDateTime { } } -#[allow(deprecated)] -impl ToPyObject for DateTime { - fn to_object(&self, py: Python<'_>) -> PyObject { - // FIXME: convert to better timezone representation here than just convert to fixed offset - // See https://github.com/PyO3/pyo3/issues/3266 - let tz = self.offset().fix().to_object(py); - let tz = tz.bind(py).downcast().unwrap(); - naive_datetime_to_py_datetime(py, &self.naive_local(), Some(tz)) - } -} - -#[allow(deprecated)] -impl IntoPy for DateTime { - fn into_py(self, py: Python<'_>) -> PyObject { - self.to_object(py) - } -} - impl<'py, Tz: TimeZone> IntoPyObject<'py> for DateTime where Tz: IntoPyObject<'py>, @@ -536,22 +452,6 @@ impl FromPyObject<'py>> FromPyObject<'_> for DateTime) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for FixedOffset { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for FixedOffset { #[cfg(Py_LIMITED_API)] type Target = PyAny; @@ -621,22 +521,6 @@ impl FromPyObject<'_> for FixedOffset { } } -#[allow(deprecated)] -impl ToPyObject for Utc { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Utc { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for Utc { #[cfg(Py_LIMITED_API)] type Target = PyAny; @@ -722,35 +606,6 @@ impl From<&NaiveTime> for TimeArgs { } } -fn naive_datetime_to_py_datetime( - py: Python<'_>, - naive_datetime: &NaiveDateTime, - #[cfg(not(Py_LIMITED_API))] tzinfo: Option<&Bound<'_, PyTzInfo>>, - #[cfg(Py_LIMITED_API)] tzinfo: Option<&Bound<'_, PyAny>>, -) -> PyObject { - let DateArgs { year, month, day } = (&naive_datetime.date()).into(); - let TimeArgs { - hour, - min, - sec, - micro, - truncated_leap_second, - } = (&naive_datetime.time()).into(); - #[cfg(not(Py_LIMITED_API))] - let datetime = PyDateTime::new(py, year, month, day, hour, min, sec, micro, tzinfo) - .expect("failed to construct datetime"); - #[cfg(Py_LIMITED_API)] - let datetime = DatetimeTypes::get(py) - .datetime - .bind(py) - .call1((year, month, day, hour, min, sec, micro, tzinfo)) - .expect("failed to construct datetime.datetime"); - if truncated_leap_second { - warn_truncated_leap_second(&datetime); - } - datetime.into() -} - fn warn_truncated_leap_second(obj: &Bound<'_, PyAny>) { let py = obj.py(); if let Err(e) = PyErr::warn( diff --git a/src/conversions/chrono_tz.rs b/src/conversions/chrono_tz.rs index 60a3bab4918..d564bcca87b 100644 --- a/src/conversions/chrono_tz.rs +++ b/src/conversions/chrono_tz.rs @@ -39,28 +39,10 @@ use crate::exceptions::PyValueError; use crate::pybacked::PyBackedStr; use crate::sync::GILOnceCell; use crate::types::{any::PyAnyMethods, PyType}; -use crate::{intern, Bound, FromPyObject, Py, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{intern, Bound, FromPyObject, Py, PyAny, PyErr, PyResult, Python}; use chrono_tz::Tz; use std::str::FromStr; -#[allow(deprecated)] -impl ToPyObject for Tz { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Tz { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().unbind() - } -} - impl<'py> IntoPyObject<'py> for Tz { type Target = PyAny; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/either.rs b/src/conversions/either.rs index a514b1fde8d..7e8e3bfc2dc 100644 --- a/src/conversions/either.rs +++ b/src/conversions/either.rs @@ -48,28 +48,10 @@ use crate::inspect::types::TypeInfo; use crate::{ exceptions::PyTypeError, types::any::PyAnyMethods, Bound, FromPyObject, IntoPyObject, - IntoPyObjectExt, PyAny, PyErr, PyObject, PyResult, Python, + IntoPyObjectExt, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use either::Either; -#[cfg_attr(docsrs, doc(cfg(feature = "either")))] -#[allow(deprecated)] -impl IntoPy for Either -where - L: IntoPy, - R: IntoPy, -{ - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - match self { - Either::Left(l) => l.into_py(py), - Either::Right(r) => r.into_py(py), - } - } -} - #[cfg_attr(docsrs, doc(cfg(feature = "either")))] impl<'py, L, R> IntoPyObject<'py> for Either where @@ -106,22 +88,6 @@ where } } -#[cfg_attr(docsrs, doc(cfg(feature = "either")))] -#[allow(deprecated)] -impl ToPyObject for Either -where - L: ToPyObject, - R: ToPyObject, -{ - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - match self { - Either::Left(l) => l.to_object(py), - Either::Right(r) => r.to_object(py), - } - } -} - #[cfg_attr(docsrs, doc(cfg(feature = "either")))] impl<'py, L, R> FromPyObject<'py> for Either where diff --git a/src/conversions/hashbrown.rs b/src/conversions/hashbrown.rs index 0efe7f5161f..c302d28d2a1 100644 --- a/src/conversions/hashbrown.rs +++ b/src/conversions/hashbrown.rs @@ -22,47 +22,13 @@ use crate::{ any::PyAnyMethods, dict::PyDictMethods, frozenset::PyFrozenSetMethods, - set::{new_from_iter, try_new_from_iter, PySetMethods}, + set::{try_new_from_iter, PySetMethods}, PyDict, PyFrozenSet, PySet, }, - Bound, FromPyObject, PyAny, PyErr, PyObject, PyResult, Python, + Bound, FromPyObject, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::{cmp, hash}; -#[allow(deprecated)] -impl ToPyObject for hashbrown::HashMap -where - K: hash::Hash + cmp::Eq + ToPyObject, - V: ToPyObject, - H: hash::BuildHasher, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.to_object(py), v.to_object(py)).unwrap(); - } - dict.into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for hashbrown::HashMap -where - K: hash::Hash + cmp::Eq + IntoPy, - V: IntoPy, - H: hash::BuildHasher, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.into_py(py), v.into_py(py)).unwrap(); - } - dict.into_any().unbind() - } -} - impl<'py, K, V, H> IntoPyObject<'py> for hashbrown::HashMap where K: IntoPyObject<'py> + cmp::Eq + hash::Hash, @@ -117,31 +83,6 @@ where } } -#[allow(deprecated)] -impl ToPyObject for hashbrown::HashSet -where - T: hash::Hash + Eq + ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - new_from_iter(py, self) - .expect("Failed to create Python set from hashbrown::HashSet") - .into() - } -} - -#[allow(deprecated)] -impl IntoPy for hashbrown::HashSet -where - K: IntoPy + Eq + hash::Hash, - S: hash::BuildHasher + Default, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - new_from_iter(py, self.into_iter().map(|item| item.into_py(py))) - .expect("Failed to create Python set from hashbrown::HashSet") - .into() - } -} - impl<'py, K, H> IntoPyObject<'py> for hashbrown::HashSet where K: IntoPyObject<'py> + cmp::Eq + hash::Hash, diff --git a/src/conversions/indexmap.rs b/src/conversions/indexmap.rs index e3787e68091..d6995c14db2 100644 --- a/src/conversions/indexmap.rs +++ b/src/conversions/indexmap.rs @@ -89,43 +89,9 @@ use crate::conversion::IntoPyObject; use crate::types::*; -use crate::{Bound, FromPyObject, PyErr, PyObject, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{Bound, FromPyObject, PyErr, Python}; use std::{cmp, hash}; -#[allow(deprecated)] -impl ToPyObject for indexmap::IndexMap -where - K: hash::Hash + cmp::Eq + ToPyObject, - V: ToPyObject, - H: hash::BuildHasher, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.to_object(py), v.to_object(py)).unwrap(); - } - dict.into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for indexmap::IndexMap -where - K: hash::Hash + cmp::Eq + IntoPy, - V: IntoPy, - H: hash::BuildHasher, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.into_py(py), v.into_py(py)).unwrap(); - } - dict.into_any().unbind() - } -} - impl<'py, K, V, H> IntoPyObject<'py> for indexmap::IndexMap where K: IntoPyObject<'py> + cmp::Eq + hash::Hash, diff --git a/src/conversions/num_bigint.rs b/src/conversions/num_bigint.rs index b3a1ac12531..ebc4058b1a6 100644 --- a/src/conversions/num_bigint.rs +++ b/src/conversions/num_bigint.rs @@ -54,10 +54,8 @@ use crate::{ ffi, instance::Bound, types::{any::PyAnyMethods, PyInt}, - FromPyObject, Py, PyAny, PyErr, PyObject, PyResult, Python, + FromPyObject, Py, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use num_bigint::{BigInt, BigUint}; @@ -67,24 +65,6 @@ use num_bigint::Sign; // for identical functionality between BigInt and BigUint macro_rules! bigint_conversion { ($rust_ty: ty, $is_signed: literal, $to_bytes: path) => { - #[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))] - #[allow(deprecated)] - impl ToPyObject for $rust_ty { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - - #[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))] - #[allow(deprecated)] - impl IntoPy for $rust_ty { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - #[cfg_attr(docsrs, doc(cfg(feature = "num-bigint")))] impl<'py> IntoPyObject<'py> for $rust_ty { type Target = PyInt; diff --git a/src/conversions/num_complex.rs b/src/conversions/num_complex.rs index db981a4179b..e9fb1096ff5 100644 --- a/src/conversions/num_complex.rs +++ b/src/conversions/num_complex.rs @@ -93,13 +93,11 @@ //! result = get_eigenvalues(m11,m12,m21,m22) //! assert result == [complex(1,-1), complex(-2,0)] //! ``` -#[allow(deprecated)] -use crate::ToPyObject; use crate::{ ffi, ffi_ptr_ext::FfiPtrExt, types::{any::PyAnyMethods, PyComplex}, - Bound, FromPyObject, PyAny, PyErr, PyObject, PyResult, Python, + Bound, FromPyObject, PyAny, PyErr, PyResult, Python, }; use num_complex::Complex; use std::os::raw::c_double; @@ -120,27 +118,6 @@ impl PyComplex { macro_rules! complex_conversion { ($float: ty) => { - #[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] - #[allow(deprecated)] - impl ToPyObject for Complex<$float> { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - crate::IntoPy::::into_py(self.to_owned(), py) - } - } - - #[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] - #[allow(deprecated)] - impl crate::IntoPy for Complex<$float> { - fn into_py(self, py: Python<'_>) -> PyObject { - unsafe { - let raw_obj = - ffi::PyComplex_FromDoubles(self.re as c_double, self.im as c_double); - PyObject::from_owned_ptr(py, raw_obj) - } - } - } - #[cfg_attr(docsrs, doc(cfg(feature = "num-complex")))] impl<'py> crate::conversion::IntoPyObject<'py> for Complex<$float> { type Target = PyComplex; diff --git a/src/conversions/num_rational.rs b/src/conversions/num_rational.rs index d86a99f2632..dfdd80cf54f 100644 --- a/src/conversions/num_rational.rs +++ b/src/conversions/num_rational.rs @@ -48,9 +48,7 @@ use crate::ffi; use crate::sync::GILOnceCell; use crate::types::any::PyAnyMethods; use crate::types::PyType; -use crate::{Bound, FromPyObject, Py, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{Bound, FromPyObject, Py, PyAny, PyErr, PyResult, Python}; #[cfg(feature = "num-bigint")] use num_bigint::BigInt; @@ -84,21 +82,6 @@ macro_rules! rational_conversion { } } - #[allow(deprecated)] - impl ToPyObject for Ratio<$int> { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - #[allow(deprecated)] - impl IntoPy for Ratio<$int> { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - impl<'py> IntoPyObject<'py> for Ratio<$int> { type Target = PyAny; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/rust_decimal.rs b/src/conversions/rust_decimal.rs index 882efa847e2..392971a0b4b 100644 --- a/src/conversions/rust_decimal.rs +++ b/src/conversions/rust_decimal.rs @@ -55,9 +55,7 @@ use crate::sync::GILOnceCell; use crate::types::any::PyAnyMethods; use crate::types::string::PyStringMethods; use crate::types::PyType; -use crate::{Bound, FromPyObject, Py, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{Bound, FromPyObject, Py, PyAny, PyErr, PyResult, Python}; use rust_decimal::Decimal; use std::str::FromStr; @@ -82,22 +80,6 @@ fn get_decimal_cls(py: Python<'_>) -> PyResult<&Bound<'_, PyType>> { DECIMAL_CLS.import(py, "decimal", "Decimal") } -#[allow(deprecated)] -impl ToPyObject for Decimal { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Decimal { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for Decimal { type Target = PyAny; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/smallvec.rs b/src/conversions/smallvec.rs index 99244d81417..d4229bc2865 100644 --- a/src/conversions/smallvec.rs +++ b/src/conversions/smallvec.rs @@ -20,38 +20,11 @@ use crate::exceptions::PyTypeError; #[cfg(feature = "experimental-inspect")] use crate::inspect::types::TypeInfo; use crate::types::any::PyAnyMethods; -use crate::types::list::new_from_iter; use crate::types::{PySequence, PyString}; use crate::PyErr; -use crate::{err::DowncastError, ffi, Bound, FromPyObject, PyAny, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{err::DowncastError, ffi, Bound, FromPyObject, PyAny, PyResult, Python}; use smallvec::{Array, SmallVec}; -#[allow(deprecated)] -impl ToPyObject for SmallVec -where - A: Array, - A::Item: ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - self.as_slice().to_object(py) - } -} - -#[allow(deprecated)] -impl IntoPy for SmallVec -where - A: Array, - A::Item: IntoPy, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - let mut iter = self.into_iter().map(|e| e.into_py(py)); - let list = new_from_iter(py, &mut iter); - list.into() - } -} - impl<'py, A> IntoPyObject<'py> for SmallVec where A: Array, @@ -142,17 +115,6 @@ mod tests { use super::*; use crate::types::{PyBytes, PyBytesMethods, PyDict, PyList}; - #[test] - #[allow(deprecated)] - fn test_smallvec_into_py() { - Python::with_gil(|py| { - let sv: SmallVec<[u64; 8]> = [1, 2, 3, 4, 5].iter().cloned().collect(); - let hso: PyObject = sv.clone().into_py(py); - let l = PyList::new(py, [1, 2, 3, 4, 5]).unwrap(); - assert!(l.eq(hso).unwrap()); - }); - } - #[test] fn test_smallvec_from_py_object() { Python::with_gil(|py| { diff --git a/src/conversions/std/array.rs b/src/conversions/std/array.rs index 1c33a610273..36db5ec640f 100644 --- a/src/conversions/std/array.rs +++ b/src/conversions/std/array.rs @@ -2,40 +2,8 @@ use crate::conversion::IntoPyObject; use crate::instance::Bound; use crate::types::any::PyAnyMethods; use crate::types::PySequence; -use crate::{err::DowncastError, ffi, FromPyObject, Py, PyAny, PyObject, PyResult, Python}; +use crate::{err::DowncastError, ffi, FromPyObject, PyAny, PyResult, Python}; use crate::{exceptions, PyErr}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; - -#[allow(deprecated)] -impl IntoPy for [T; N] -where - T: IntoPy, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - unsafe { - let len = N as ffi::Py_ssize_t; - - let ptr = ffi::PyList_New(len); - - // We create the `Py` pointer here for two reasons: - // - panics if the ptr is null - // - its Drop cleans up the list if user code panics. - let list: Py = Py::from_owned_ptr(py, ptr); - - for (i, obj) in (0..len).zip(self) { - let obj = obj.into_py(py).into_ptr(); - - #[cfg(not(Py_LIMITED_API))] - ffi::PyList_SET_ITEM(ptr, i, obj); - #[cfg(Py_LIMITED_API)] - ffi::PyList_SetItem(ptr, i, obj); - } - - list - } - } -} impl<'py, T, const N: usize> IntoPyObject<'py> for [T; N] where @@ -69,16 +37,6 @@ where } } -#[allow(deprecated)] -impl ToPyObject for [T; N] -where - T: ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - self.as_ref().to_object(py) - } -} - impl<'py, T, const N: usize> FromPyObject<'py> for [T; N] where T: FromPyObject<'py>, diff --git a/src/conversions/std/cell.rs b/src/conversions/std/cell.rs index 70da688b70c..983a0350228 100644 --- a/src/conversions/std/cell.rs +++ b/src/conversions/std/cell.rs @@ -1,24 +1,10 @@ use std::cell::Cell; use crate::{ - conversion::IntoPyObject, types::any::PyAnyMethods, Bound, FromPyObject, PyAny, PyObject, - PyResult, Python, + conversion::IntoPyObject, types::any::PyAnyMethods, Bound, FromPyObject, PyAny, PyResult, + Python, }; -#[allow(deprecated)] -impl crate::ToPyObject for Cell { - fn to_object(&self, py: Python<'_>) -> PyObject { - self.get().to_object(py) - } -} - -#[allow(deprecated)] -impl> crate::IntoPy for Cell { - fn into_py(self, py: Python<'_>) -> PyObject { - self.get().into_py(py) - } -} - impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for Cell { type Target = T::Target; type Output = T::Output; diff --git a/src/conversions/std/ipaddr.rs b/src/conversions/std/ipaddr.rs index 7ba8da87749..76f6a6927c2 100755 --- a/src/conversions/std/ipaddr.rs +++ b/src/conversions/std/ipaddr.rs @@ -7,9 +7,7 @@ use crate::sync::GILOnceCell; use crate::types::any::PyAnyMethods; use crate::types::string::PyStringMethods; use crate::types::PyType; -use crate::{intern, FromPyObject, Py, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{intern, FromPyObject, Py, PyAny, PyErr, PyResult, Python}; impl FromPyObject<'_> for IpAddr { fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult { @@ -31,14 +29,6 @@ impl FromPyObject<'_> for IpAddr { } } -#[allow(deprecated)] -impl ToPyObject for Ipv4Addr { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().unbind() - } -} - impl<'py> IntoPyObject<'py> for Ipv4Addr { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -63,14 +53,6 @@ impl<'py> IntoPyObject<'py> for &Ipv4Addr { } } -#[allow(deprecated)] -impl ToPyObject for Ipv6Addr { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().unbind() - } -} - impl<'py> IntoPyObject<'py> for Ipv6Addr { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -95,22 +77,6 @@ impl<'py> IntoPyObject<'py> for &Ipv6Addr { } } -#[allow(deprecated)] -impl ToPyObject for IpAddr { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for IpAddr { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().unbind() - } -} - impl<'py> IntoPyObject<'py> for IpAddr { type Target = PyAny; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/std/map.rs b/src/conversions/std/map.rs index 8a6ba57012e..b472957d1b1 100644 --- a/src/conversions/std/map.rs +++ b/src/conversions/std/map.rs @@ -6,57 +6,8 @@ use crate::{ conversion::IntoPyObject, instance::Bound, types::{any::PyAnyMethods, dict::PyDictMethods, PyDict}, - FromPyObject, PyAny, PyErr, PyObject, Python, + FromPyObject, PyAny, PyErr, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; - -#[allow(deprecated)] -impl ToPyObject for collections::HashMap -where - K: hash::Hash + cmp::Eq + ToPyObject, - V: ToPyObject, - H: hash::BuildHasher, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.to_object(py), v.to_object(py)).unwrap(); - } - dict.into_any().unbind() - } -} - -#[allow(deprecated)] -impl ToPyObject for collections::BTreeMap -where - K: cmp::Eq + ToPyObject, - V: ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.to_object(py), v.to_object(py)).unwrap(); - } - dict.into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for collections::HashMap -where - K: hash::Hash + cmp::Eq + IntoPy, - V: IntoPy, - H: hash::BuildHasher, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.into_py(py), v.into_py(py)).unwrap(); - } - dict.into_any().unbind() - } -} impl<'py, K, V, H> IntoPyObject<'py> for collections::HashMap where @@ -108,21 +59,6 @@ where } } -#[allow(deprecated)] -impl IntoPy for collections::BTreeMap -where - K: cmp::Eq + IntoPy, - V: IntoPy, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - let dict = PyDict::new(py); - for (k, v) in self { - dict.set_item(k.into_py(py), v.into_py(py)).unwrap(); - } - dict.into_any().unbind() - } -} - impl<'py, K, V> IntoPyObject<'py> for collections::BTreeMap where K: IntoPyObject<'py> + cmp::Eq, diff --git a/src/conversions/std/num.rs b/src/conversions/std/num.rs index 0450c591ae8..40073d8af69 100644 --- a/src/conversions/std/num.rs +++ b/src/conversions/std/num.rs @@ -5,9 +5,7 @@ use crate::ffi_ptr_ext::FfiPtrExt; use crate::inspect::types::TypeInfo; use crate::types::any::PyAnyMethods; use crate::types::{PyBytes, PyInt}; -use crate::{exceptions, ffi, Bound, FromPyObject, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{exceptions, ffi, Bound, FromPyObject, PyAny, PyErr, PyResult, Python}; use std::convert::Infallible; use std::num::{ NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, @@ -17,21 +15,6 @@ use std::os::raw::c_long; macro_rules! int_fits_larger_int { ($rust_type:ty, $larger_type:ty) => { - #[allow(deprecated)] - impl ToPyObject for $rust_type { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - #[allow(deprecated)] - impl IntoPy for $rust_type { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - impl<'py> IntoPyObject<'py> for $rust_type { type Target = PyInt; type Output = Bound<'py, Self::Target>; @@ -104,20 +87,6 @@ macro_rules! extract_int { macro_rules! int_convert_u64_or_i64 { ($rust_type:ty, $pylong_from_ll_or_ull:expr, $pylong_as_ll_or_ull:expr, $force_index_call:literal) => { - #[allow(deprecated)] - impl ToPyObject for $rust_type { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - #[allow(deprecated)] - impl IntoPy for $rust_type { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } impl<'py> IntoPyObject<'py> for $rust_type { type Target = PyInt; type Output = Bound<'py, Self::Target>; @@ -166,21 +135,6 @@ macro_rules! int_convert_u64_or_i64 { macro_rules! int_fits_c_long { ($rust_type:ty) => { - #[allow(deprecated)] - impl ToPyObject for $rust_type { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - #[allow(deprecated)] - impl IntoPy for $rust_type { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - impl<'py> IntoPyObject<'py> for $rust_type { type Target = PyInt; type Output = Bound<'py, Self::Target>; @@ -231,20 +185,6 @@ macro_rules! int_fits_c_long { }; } -#[allow(deprecated)] -impl ToPyObject for u8 { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} -#[allow(deprecated)] -impl IntoPy for u8 { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} impl<'py> IntoPyObject<'py> for u8 { type Target = PyInt; type Output = Bound<'py, Self::Target>; @@ -356,22 +296,6 @@ mod fast_128bit_int_conversion { // for 128bit Integers macro_rules! int_convert_128 { ($rust_type: ty, $is_signed: literal) => { - #[allow(deprecated)] - impl ToPyObject for $rust_type { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - - #[allow(deprecated)] - impl IntoPy for $rust_type { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - impl<'py> IntoPyObject<'py> for $rust_type { type Target = PyInt; type Output = Bound<'py, Self::Target>; @@ -510,22 +434,6 @@ mod slow_128bit_int_conversion { // for 128bit Integers macro_rules! int_convert_128 { ($rust_type: ty, $half_type: ty) => { - #[allow(deprecated)] - impl ToPyObject for $rust_type { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - - #[allow(deprecated)] - impl IntoPy for $rust_type { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - impl<'py> IntoPyObject<'py> for $rust_type { type Target = PyInt; type Output = Bound<'py, Self::Target>; @@ -577,11 +485,11 @@ mod slow_128bit_int_conversion { ffi::PyLong_AsUnsignedLongLongMask(ob.as_ptr()), )? as $rust_type; let shift = SHIFT.into_pyobject(py)?; - let shifted = PyObject::from_owned_ptr_or_err( + let shifted = Bound::from_owned_ptr_or_err( py, ffi::PyNumber_Rshift(ob.as_ptr(), shift.as_ptr()), )?; - let upper: $half_type = shifted.extract(py)?; + let upper: $half_type = shifted.extract()?; Ok((<$rust_type>::from(upper) << SHIFT) | lower) } } @@ -614,22 +522,6 @@ fn err_if_invalid_value( macro_rules! nonzero_int_impl { ($nonzero_type:ty, $primitive_type:ty) => { - #[allow(deprecated)] - impl ToPyObject for $nonzero_type { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - - #[allow(deprecated)] - impl IntoPy for $nonzero_type { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } - } - impl<'py> IntoPyObject<'py> for $nonzero_type { type Target = PyInt; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/std/option.rs b/src/conversions/std/option.rs index aac8c7ab210..cd5edec7d6d 100644 --- a/src/conversions/std/option.rs +++ b/src/conversions/std/option.rs @@ -1,31 +1,8 @@ use crate::{ conversion::IntoPyObject, ffi, types::any::PyAnyMethods, AsPyPointer, Bound, BoundObject, - FromPyObject, PyAny, PyObject, PyResult, Python, + FromPyObject, PyAny, PyResult, Python, }; -/// `Option::Some` is converted like `T`. -/// `Option::None` is converted to Python `None`. -#[allow(deprecated)] -impl crate::ToPyObject for Option -where - T: crate::ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - self.as_ref() - .map_or_else(|| py.None(), |val| val.to_object(py)) - } -} - -#[allow(deprecated)] -impl crate::IntoPy for Option -where - T: crate::IntoPy, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - self.map_or_else(|| py.None(), |val| val.into_py(py)) - } -} - impl<'py, T> IntoPyObject<'py> for Option where T: IntoPyObject<'py>, diff --git a/src/conversions/std/osstr.rs b/src/conversions/std/osstr.rs index 70b5bd152ac..39fa56f373d 100644 --- a/src/conversions/std/osstr.rs +++ b/src/conversions/std/osstr.rs @@ -3,21 +3,11 @@ use crate::ffi_ptr_ext::FfiPtrExt; use crate::instance::Bound; use crate::types::any::PyAnyMethods; use crate::types::PyString; -use crate::{ffi, FromPyObject, PyAny, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{ffi, FromPyObject, PyAny, PyResult, Python}; use std::borrow::Cow; use std::convert::Infallible; use std::ffi::{OsStr, OsString}; -#[allow(deprecated)] -impl ToPyObject for OsStr { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for &OsStr { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -134,30 +124,6 @@ impl FromPyObject<'_> for OsString { } } -#[allow(deprecated)] -impl IntoPy for &'_ OsStr { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl ToPyObject for Cow<'_, OsStr> { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Cow<'_, OsStr> { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for Cow<'_, OsStr> { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -180,22 +146,6 @@ impl<'py> IntoPyObject<'py> for &Cow<'_, OsStr> { } } -#[allow(deprecated)] -impl ToPyObject for OsString { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for OsString { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for OsString { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -207,14 +157,6 @@ impl<'py> IntoPyObject<'py> for OsString { } } -#[allow(deprecated)] -impl IntoPy for &OsString { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for &OsString { type Target = PyString; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/std/path.rs b/src/conversions/std/path.rs index 25765a8084e..3eb074d04d2 100644 --- a/src/conversions/std/path.rs +++ b/src/conversions/std/path.rs @@ -3,21 +3,11 @@ use crate::ffi_ptr_ext::FfiPtrExt; use crate::instance::Bound; use crate::sync::GILOnceCell; use crate::types::any::PyAnyMethods; -use crate::{ffi, FromPyObject, IntoPyObjectExt, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{ffi, FromPyObject, PyAny, PyErr, PyObject, PyResult, Python}; use std::borrow::Cow; use std::ffi::OsString; use std::path::{Path, PathBuf}; -#[allow(deprecated)] -impl ToPyObject for Path { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.as_os_str().into_py_any(py).unwrap() - } -} - // See osstr.rs for why there's no FromPyObject impl for &Path impl FromPyObject<'_> for PathBuf { @@ -28,14 +18,6 @@ impl FromPyObject<'_> for PathBuf { } } -#[allow(deprecated)] -impl IntoPy for &Path { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.to_object(py) - } -} - impl<'py> IntoPyObject<'py> for &Path { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -61,22 +43,6 @@ impl<'py> IntoPyObject<'py> for &&Path { } } -#[allow(deprecated)] -impl ToPyObject for Cow<'_, Path> { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - (**self).to_object(py) - } -} - -#[allow(deprecated)] -impl IntoPy for Cow<'_, Path> { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - (*self).to_object(py) - } -} - impl<'py> IntoPyObject<'py> for Cow<'_, Path> { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -99,22 +65,6 @@ impl<'py> IntoPyObject<'py> for &Cow<'_, Path> { } } -#[allow(deprecated)] -impl ToPyObject for PathBuf { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - (**self).to_object(py) - } -} - -#[allow(deprecated)] -impl IntoPy for PathBuf { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - (*self).to_object(py) - } -} - impl<'py> IntoPyObject<'py> for PathBuf { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -126,14 +76,6 @@ impl<'py> IntoPyObject<'py> for PathBuf { } } -#[allow(deprecated)] -impl IntoPy for &PathBuf { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - (**self).to_object(py) - } -} - impl<'py> IntoPyObject<'py> for &PathBuf { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -147,8 +89,8 @@ impl<'py> IntoPyObject<'py> for &PathBuf { #[cfg(test)] mod tests { - use crate::types::{PyAnyMethods, PyString, PyStringMethods}; - use crate::{IntoPyObject, IntoPyObjectExt, PyObject, Python}; + use crate::types::{PyAnyMethods, PyString}; + use crate::{IntoPyObject, IntoPyObjectExt, Python}; use std::borrow::Cow; use std::fmt::Debug; use std::path::{Path, PathBuf}; @@ -203,28 +145,4 @@ mod tests { assert_eq!(roundtrip, Path::new(path)); }); } - - #[test] - #[allow(deprecated)] - fn test_intopy_string() { - use crate::IntoPy; - - Python::with_gil(|py| { - fn test_roundtrip(py: Python<'_>, obj: T) - where - T: IntoPy + AsRef + Debug + Clone, - { - let pyobject = obj.clone().into_py(py).into_bound(py); - let pystring = pyobject.downcast_exact::().unwrap(); - assert_eq!(pystring.to_string_lossy(), obj.as_ref().to_string_lossy()); - let roundtripped_obj: PathBuf = pyobject.extract().unwrap(); - assert_eq!(obj.as_ref(), roundtripped_obj.as_path()); - } - let path = Path::new("Hello\0\n🐍"); - test_roundtrip::<&Path>(py, path); - test_roundtrip::>(py, Cow::Borrowed(path)); - test_roundtrip::>(py, Cow::Owned(path.to_path_buf())); - test_roundtrip::(py, path.to_path_buf()); - }); - } } diff --git a/src/conversions/std/set.rs b/src/conversions/std/set.rs index 3f1e6733f1a..ebb737f72c6 100644 --- a/src/conversions/std/set.rs +++ b/src/conversions/std/set.rs @@ -8,51 +8,11 @@ use crate::{ types::{ any::PyAnyMethods, frozenset::PyFrozenSetMethods, - set::{new_from_iter, try_new_from_iter, PySetMethods}, + set::{try_new_from_iter, PySetMethods}, PyFrozenSet, PySet, }, - FromPyObject, PyAny, PyErr, PyObject, PyResult, Python, + FromPyObject, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; - -#[allow(deprecated)] -impl ToPyObject for collections::HashSet -where - T: hash::Hash + Eq + ToPyObject, - S: hash::BuildHasher + Default, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - new_from_iter(py, self) - .expect("Failed to create Python set from HashSet") - .into() - } -} - -#[allow(deprecated)] -impl ToPyObject for collections::BTreeSet -where - T: hash::Hash + Eq + ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - new_from_iter(py, self) - .expect("Failed to create Python set from BTreeSet") - .into() - } -} - -#[allow(deprecated)] -impl IntoPy for collections::HashSet -where - K: IntoPy + Eq + hash::Hash, - S: hash::BuildHasher + Default, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - new_from_iter(py, self.into_iter().map(|item| item.into_py(py))) - .expect("Failed to create Python set from HashSet") - .into() - } -} impl<'py, K, S> IntoPyObject<'py> for collections::HashSet where @@ -117,18 +77,6 @@ where } } -#[allow(deprecated)] -impl IntoPy for collections::BTreeSet -where - K: IntoPy + cmp::Ord, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - new_from_iter(py, self.into_iter().map(|item| item.into_py(py))) - .expect("Failed to create Python set from BTreeSet") - .into() - } -} - impl<'py, K> IntoPyObject<'py> for collections::BTreeSet where K: IntoPyObject<'py> + cmp::Ord, @@ -192,7 +140,7 @@ where #[cfg(test)] mod tests { use crate::types::{any::PyAnyMethods, PyFrozenSet, PySet}; - use crate::{IntoPyObject, PyObject, Python}; + use crate::{IntoPyObject, Python}; use std::collections::{BTreeSet, HashSet}; #[test] @@ -221,22 +169,6 @@ mod tests { }); } - #[test] - #[allow(deprecated)] - fn test_set_into_py() { - use crate::IntoPy; - Python::with_gil(|py| { - let bt: BTreeSet = [1, 2, 3, 4, 5].iter().cloned().collect(); - let hs: HashSet = [1, 2, 3, 4, 5].iter().cloned().collect(); - - let bto: PyObject = bt.clone().into_py(py); - let hso: PyObject = hs.clone().into_py(py); - - assert_eq!(bt, bto.extract(py).unwrap()); - assert_eq!(hs, hso.extract(py).unwrap()); - }); - } - #[test] fn test_set_into_pyobject() { Python::with_gil(|py| { diff --git a/src/conversions/std/slice.rs b/src/conversions/std/slice.rs index 798e5b54c45..5bfa5a3d48d 100644 --- a/src/conversions/std/slice.rs +++ b/src/conversions/std/slice.rs @@ -5,17 +5,8 @@ use crate::inspect::types::TypeInfo; use crate::{ conversion::IntoPyObject, types::{PyByteArray, PyByteArrayMethods, PyBytes}, - Bound, Py, PyAny, PyErr, PyObject, PyResult, Python, + Bound, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; - -#[allow(deprecated)] -impl IntoPy for &[u8] { - fn into_py(self, py: Python<'_>) -> PyObject { - PyBytes::new(py, self).unbind().into() - } -} impl<'a, 'py, T> IntoPyObject<'py> for &'a [T] where @@ -76,20 +67,6 @@ impl<'a> crate::conversion::FromPyObjectBound<'a, '_> for Cow<'a, [u8]> { } } -#[allow(deprecated)] -impl ToPyObject for Cow<'_, [u8]> { - fn to_object(&self, py: Python<'_>) -> Py { - PyBytes::new(py, self.as_ref()).into() - } -} - -#[allow(deprecated)] -impl IntoPy> for Cow<'_, [u8]> { - fn into_py(self, py: Python<'_>) -> Py { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py, T> IntoPyObject<'py> for Cow<'_, [T]> where T: Clone, diff --git a/src/conversions/std/string.rs b/src/conversions/std/string.rs index 074b5c2ba73..8936bd35000 100644 --- a/src/conversions/std/string.rs +++ b/src/conversions/std/string.rs @@ -6,36 +6,8 @@ use crate::{ conversion::IntoPyObject, instance::Bound, types::{any::PyAnyMethods, string::PyStringMethods, PyString}, - FromPyObject, Py, PyAny, PyObject, PyResult, Python, + FromPyObject, PyAny, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; - -/// Converts a Rust `str` to a Python object. -/// See `PyString::new` for details on the conversion. -#[allow(deprecated)] -impl ToPyObject for str { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for &str { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy> for &str { - #[inline] - fn into_py(self, py: Python<'_>) -> Py { - self.into_pyobject(py).unwrap().unbind() - } -} impl<'py> IntoPyObject<'py> for &str { type Target = PyString; @@ -69,24 +41,6 @@ impl<'py> IntoPyObject<'py> for &&str { } } -/// Converts a Rust `Cow<'_, str>` to a Python object. -/// See `PyString::new` for details on the conversion. -#[allow(deprecated)] -impl ToPyObject for Cow<'_, str> { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Cow<'_, str> { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for Cow<'_, str> { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -119,32 +73,6 @@ impl<'py> IntoPyObject<'py> for &Cow<'_, str> { } } -/// Converts a Rust `String` to a Python object. -/// See `PyString::new` for details on the conversion. -#[allow(deprecated)] -impl ToPyObject for String { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl ToPyObject for char { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for char { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for char { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -177,14 +105,6 @@ impl<'py> IntoPyObject<'py> for &char { } } -#[allow(deprecated)] -impl IntoPy for String { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for String { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -200,14 +120,6 @@ impl<'py> IntoPyObject<'py> for String { } } -#[allow(deprecated)] -impl IntoPy for &String { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for &String { type Target = PyString; type Output = Bound<'py, Self::Target>; @@ -282,22 +194,9 @@ impl FromPyObject<'_> for char { #[cfg(test)] mod tests { use crate::types::any::PyAnyMethods; - use crate::{IntoPyObject, PyObject, Python}; + use crate::{IntoPyObject, Python}; use std::borrow::Cow; - #[test] - #[allow(deprecated)] - fn test_cow_into_py() { - use crate::IntoPy; - Python::with_gil(|py| { - let s = "Hello Python"; - let py_string: PyObject = Cow::Borrowed(s).into_py(py); - assert_eq!(s, py_string.extract::>(py).unwrap()); - let py_string: PyObject = Cow::::Owned(s.into()).into_py(py); - assert_eq!(s, py_string.extract::>(py).unwrap()); - }) - } - #[test] fn test_cow_into_pyobject() { Python::with_gil(|py| { diff --git a/src/conversions/std/time.rs b/src/conversions/std/time.rs index 741c28ee905..549eb4b5865 100755 --- a/src/conversions/std/time.rs +++ b/src/conversions/std/time.rs @@ -9,8 +9,6 @@ use crate::types::{timezone_utc, PyDateTime, PyDelta, PyDeltaAccess}; #[cfg(Py_LIMITED_API)] use crate::Py; use crate::{intern, Bound, FromPyObject, PyAny, PyErr, PyObject, PyResult, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; const SECONDS_PER_DAY: u64 = 24 * 60 * 60; @@ -52,22 +50,6 @@ impl FromPyObject<'_> for Duration { } } -#[allow(deprecated)] -impl ToPyObject for Duration { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for Duration { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for Duration { #[cfg(not(Py_LIMITED_API))] type Target = PyDelta; @@ -134,22 +116,6 @@ impl FromPyObject<'_> for SystemTime { } } -#[allow(deprecated)] -impl ToPyObject for SystemTime { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for SystemTime { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for SystemTime { type Target = PyAny; type Output = Bound<'py, Self::Target>; diff --git a/src/conversions/std/vec.rs b/src/conversions/std/vec.rs index b630ca4019a..d77c899eda9 100644 --- a/src/conversions/std/vec.rs +++ b/src/conversions/std/vec.rs @@ -1,44 +1,7 @@ use crate::conversion::IntoPyObject; #[cfg(feature = "experimental-inspect")] use crate::inspect::types::TypeInfo; -use crate::types::list::new_from_iter; -use crate::{Bound, PyAny, PyErr, PyObject, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; - -#[allow(deprecated)] -impl ToPyObject for [T] -where - T: ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - let mut iter = self.iter().map(|e| e.to_object(py)); - let list = new_from_iter(py, &mut iter); - list.into() - } -} - -#[allow(deprecated)] -impl ToPyObject for Vec -where - T: ToPyObject, -{ - fn to_object(&self, py: Python<'_>) -> PyObject { - self.as_slice().to_object(py) - } -} - -#[allow(deprecated)] -impl IntoPy for Vec -where - T: IntoPy, -{ - fn into_py(self, py: Python<'_>) -> PyObject { - let mut iter = self.into_iter().map(|e| e.into_py(py)); - let list = new_from_iter(py, &mut iter); - list.into() - } -} +use crate::{Bound, PyAny, PyErr, Python}; impl<'py, T> IntoPyObject<'py> for Vec where diff --git a/src/err/mod.rs b/src/err/mod.rs index 21e89efcf8e..ecdd4efe2eb 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -11,8 +11,6 @@ use crate::{ ffi, }; use crate::{Borrowed, BoundObject, Py, PyAny, PyObject, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::borrow::Cow; use std::ffi::CStr; @@ -695,30 +693,6 @@ impl std::fmt::Display for PyErr { impl std::error::Error for PyErr {} -#[allow(deprecated)] -impl IntoPy for PyErr { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl ToPyObject for PyErr { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for &PyErr { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for PyErr { type Target = PyBaseException; type Output = Bound<'py, Self::Target>; diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index 270ba2de47e..fccbf1610ac 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -12,8 +12,6 @@ use crate::{ Borrowed, BoundObject, IntoPyObject, IntoPyObjectExt, Py, PyAny, PyClass, PyErr, PyRef, PyResult, PyTypeInfo, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::{ borrow::Cow, ffi::{CStr, CString}, @@ -1247,8 +1245,6 @@ pub struct PyClassGetterGenerator< // additional metadata about the field which is used to switch between different implementations // at compile time const IS_PY_T: bool, - const IMPLEMENTS_TOPYOBJECT: bool, - const IMPLEMENTS_INTOPY: bool, const IMPLEMENTS_INTOPYOBJECT_REF: bool, const IMPLEMENTS_INTOPYOBJECT: bool, >(PhantomData<(ClassT, FieldT, Offset)>); @@ -1258,8 +1254,6 @@ impl< FieldT, Offset: OffsetCalculator, const IS_PY_T: bool, - const IMPLEMENTS_TOPYOBJECT: bool, - const IMPLEMENTS_INTOPY: bool, const IMPLEMENTS_INTOPYOBJECT_REF: bool, const IMPLEMENTS_INTOPYOBJECT: bool, > @@ -1268,8 +1262,6 @@ impl< FieldT, Offset, IS_PY_T, - IMPLEMENTS_TOPYOBJECT, - IMPLEMENTS_INTOPY, IMPLEMENTS_INTOPYOBJECT_REF, IMPLEMENTS_INTOPYOBJECT, > @@ -1285,8 +1277,6 @@ impl< ClassT: PyClass, U, Offset: OffsetCalculator>, - const IMPLEMENTS_TOPYOBJECT: bool, - const IMPLEMENTS_INTOPY: bool, const IMPLEMENTS_INTOPYOBJECT_REF: bool, const IMPLEMENTS_INTOPYOBJECT: bool, > @@ -1295,8 +1285,6 @@ impl< Py, Offset, true, - IMPLEMENTS_TOPYOBJECT, - IMPLEMENTS_INTOPY, IMPLEMENTS_INTOPYOBJECT_REF, IMPLEMENTS_INTOPYOBJECT, > @@ -1319,52 +1307,17 @@ impl< } else { PyMethodDefType::Getter(PyGetterDef { name, - meth: pyo3_get_value_topyobject::, Offset>, + meth: pyo3_get_value_into_pyobject_ref::, Offset>, doc, }) } } } -/// Fallback case; Field is not `Py`; try to use `ToPyObject` to avoid potentially expensive -/// clones of containers like `Vec` -#[allow(deprecated)] -impl< - ClassT: PyClass, - FieldT: ToPyObject, - Offset: OffsetCalculator, - const IMPLEMENTS_INTOPY: bool, - > PyClassGetterGenerator -{ - pub const fn generate(&self, name: &'static CStr, doc: &'static CStr) -> PyMethodDefType { - PyMethodDefType::Getter(PyGetterDef { - name, - meth: pyo3_get_value_topyobject::, - doc, - }) - } -} - /// Field is not `Py`; try to use `IntoPyObject` for `&T` (prefered over `ToPyObject`) to avoid /// potentially expensive clones of containers like `Vec` -impl< - ClassT, - FieldT, - Offset, - const IMPLEMENTS_TOPYOBJECT: bool, - const IMPLEMENTS_INTOPY: bool, - const IMPLEMENTS_INTOPYOBJECT: bool, - > - PyClassGetterGenerator< - ClassT, - FieldT, - Offset, - false, - IMPLEMENTS_TOPYOBJECT, - IMPLEMENTS_INTOPY, - true, - IMPLEMENTS_INTOPYOBJECT, - > +impl + PyClassGetterGenerator where ClassT: PyClass, for<'a, 'py> &'a FieldT: IntoPyObject<'py>, @@ -1379,51 +1332,6 @@ where } } -/// Temporary case to prefer `IntoPyObject + Clone` over `IntoPy + Clone`, while still showing the -/// `IntoPyObject` suggestion if neither is implemented; -impl - PyClassGetterGenerator< - ClassT, - FieldT, - Offset, - false, - IMPLEMENTS_TOPYOBJECT, - IMPLEMENTS_INTOPY, - false, - true, - > -where - ClassT: PyClass, - Offset: OffsetCalculator, - for<'py> FieldT: IntoPyObject<'py> + Clone, -{ - pub const fn generate(&self, name: &'static CStr, doc: &'static CStr) -> PyMethodDefType { - PyMethodDefType::Getter(PyGetterDef { - name, - meth: pyo3_get_value_into_pyobject::, - doc, - }) - } -} - -/// IntoPy + Clone fallback case, which was the only behaviour before PyO3 0.22. -#[allow(deprecated)] -impl - PyClassGetterGenerator -where - ClassT: PyClass, - Offset: OffsetCalculator, - FieldT: IntoPy> + Clone, -{ - pub const fn generate(&self, name: &'static CStr, doc: &'static CStr) -> PyMethodDefType { - PyMethodDefType::Getter(PyGetterDef { - name, - meth: pyo3_get_value::, - doc, - }) - } -} - #[cfg_attr( diagnostic_namespace, diagnostic::on_unimplemented( @@ -1436,20 +1344,24 @@ pub trait PyO3GetField<'py>: IntoPyObject<'py> + Clone {} impl<'py, T> PyO3GetField<'py> for T where T: IntoPyObject<'py> + Clone {} /// Base case attempts to use IntoPyObject + Clone -impl> - PyClassGetterGenerator +impl< + ClassT: PyClass, + FieldT, + Offset: OffsetCalculator, + const IMPLEMENTS_INTOPYOBJECT: bool, + > PyClassGetterGenerator { - pub const fn generate(&self, _name: &'static CStr, _doc: &'static CStr) -> PyMethodDefType + pub const fn generate(&self, name: &'static CStr, doc: &'static CStr) -> PyMethodDefType // The bound goes here rather than on the block so that this impl is always available // if no specialization is used instead where for<'py> FieldT: PyO3GetField<'py>, { - // unreachable not allowed in const - panic!( - "exists purely to emit diagnostics on unimplemented traits. When `ToPyObject` \ - and `IntoPy` are fully removed this will be replaced by the temporary `IntoPyObject` case above." - ) + PyMethodDefType::Getter(PyGetterDef { + name, + meth: pyo3_get_value_into_pyobject::, + doc, + }) } } @@ -1476,23 +1388,6 @@ where unsafe { obj.cast::().add(Offset::offset()).cast::() } } -#[allow(deprecated)] -fn pyo3_get_value_topyobject< - ClassT: PyClass, - FieldT: ToPyObject, - Offset: OffsetCalculator, ->( - py: Python<'_>, - obj: *mut ffi::PyObject, -) -> PyResult<*mut ffi::PyObject> { - let _holder = unsafe { ensure_no_mutable_alias::(py, &obj)? }; - let value = field_from_object::(obj); - - // SAFETY: Offset is known to describe the location of the value, and - // _holder is preventing mutable aliasing - Ok((unsafe { &*value }).to_object(py).into_ptr()) -} - fn pyo3_get_value_into_pyobject_ref( py: Python<'_>, obj: *mut ffi::PyObject, @@ -1534,23 +1429,6 @@ where .into_ptr()) } -#[allow(deprecated)] -fn pyo3_get_value< - ClassT: PyClass, - FieldT: IntoPy> + Clone, - Offset: OffsetCalculator, ->( - py: Python<'_>, - obj: *mut ffi::PyObject, -) -> PyResult<*mut ffi::PyObject> { - let _holder = unsafe { ensure_no_mutable_alias::(py, &obj)? }; - let value = field_from_object::(obj); - - // SAFETY: Offset is known to describe the location of the value, and - // _holder is preventing mutable aliasing - Ok((unsafe { &*value }).clone().into_py(py).into_ptr()) -} - pub struct ConvertField< const IMPLEMENTS_INTOPYOBJECT_REF: bool, const IMPLEMENTS_INTOPYOBJECT: bool, diff --git a/src/impl_/pyclass/probes.rs b/src/impl_/pyclass/probes.rs index 719976e89c7..001b85f5023 100644 --- a/src/impl_/pyclass/probes.rs +++ b/src/impl_/pyclass/probes.rs @@ -1,8 +1,6 @@ use std::marker::PhantomData; use crate::{conversion::IntoPyObject, Py}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; /// Trait used to combine with zero-sized types to calculate at compile time /// some property of a type. @@ -30,20 +28,6 @@ impl IsPyT> { pub const VALUE: bool = true; } -probe!(IsToPyObject); - -#[allow(deprecated)] -impl IsToPyObject { - pub const VALUE: bool = true; -} - -probe!(IsIntoPy); - -#[allow(deprecated)] -impl> IsIntoPy { - pub const VALUE: bool = true; -} - probe!(IsIntoPyObjectRef); // Possible clippy beta regression, diff --git a/src/impl_/wrap.rs b/src/impl_/wrap.rs index 7b214219408..9d14d321ae2 100644 --- a/src/impl_/wrap.rs +++ b/src/impl_/wrap.rs @@ -1,7 +1,5 @@ use std::{convert::Infallible, marker::PhantomData, ops::Deref}; -#[allow(deprecated)] -use crate::IntoPy; use crate::{ffi, types::PyNone, Bound, IntoPyObject, IntoPyObjectExt, PyObject, PyResult, Python}; /// Used to wrap values in `Option` for default arguments. @@ -108,32 +106,6 @@ impl<'py, T: IntoPyObject<'py>, E> IntoPyObjectConverter> { } } -#[allow(deprecated)] -impl> IntoPyConverter { - #[inline] - pub fn wrap(&self, obj: T) -> Result { - Ok(obj) - } -} - -#[allow(deprecated)] -impl, E> IntoPyConverter> { - #[inline] - pub fn wrap(&self, obj: Result) -> Result { - obj - } - - #[inline] - pub fn map_into_pyobject(&self, py: Python<'_>, obj: PyResult) -> PyResult { - obj.map(|obj| obj.into_py(py)) - } - - #[inline] - pub fn map_into_ptr(&self, py: Python<'_>, obj: PyResult) -> PyResult<*mut ffi::PyObject> { - obj.map(|obj| obj.into_py(py).into_ptr()) - } -} - impl UnknownReturnResultType> { #[inline] pub fn wrap<'py>(&self, _: Result) -> Result diff --git a/src/instance.rs b/src/instance.rs index a47274e7732..89e950e0d91 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -11,8 +11,6 @@ use crate::{ PyRefMut, PyTypeInfo, Python, }; use crate::{gil, PyTypeCheck}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::ops::Deref; @@ -827,24 +825,6 @@ impl Clone for Borrowed<'_, '_, T> { impl Copy for Borrowed<'_, '_, T> {} -#[allow(deprecated)] -impl ToPyObject for Borrowed<'_, '_, T> { - /// Converts `Py` instance -> PyObject. - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - (*self).into_py(py) - } -} - -#[allow(deprecated)] -impl IntoPy for Borrowed<'_, '_, T> { - /// Converts `Py` instance -> PyObject. - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.to_owned().into_py(py) - } -} - impl<'a, 'py, T> BoundObject<'py, T> for Borrowed<'a, 'py, T> { type Any = Borrowed<'a, 'py, PyAny>; @@ -1711,60 +1691,6 @@ impl Py { } } -#[allow(deprecated)] -impl ToPyObject for Py { - /// Converts `Py` instance -> PyObject. - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.clone_ref(py).into_any() - } -} - -#[allow(deprecated)] -impl IntoPy for Py { - /// Converts a `Py` instance to `PyObject`. - /// Consumes `self` without calling `Py_DECREF()`. - #[inline] - fn into_py(self, _py: Python<'_>) -> PyObject { - self.into_any() - } -} - -#[allow(deprecated)] -impl IntoPy for &'_ Py { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl ToPyObject for Bound<'_, T> { - /// Converts `&Bound` instance -> PyObject, increasing the reference count. - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.clone().into_py(py) - } -} - -#[allow(deprecated)] -impl IntoPy for Bound<'_, T> { - /// Converts a `Bound` instance to `PyObject`. - #[inline] - fn into_py(self, _py: Python<'_>) -> PyObject { - self.into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for &Bound<'_, T> { - /// Converts `&Bound` instance -> PyObject, increasing the reference count. - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - unsafe impl crate::AsPyPointer for Py { /// Gets the underlying FFI pointer, returns a borrowed pointer. #[inline] diff --git a/src/lib.rs b/src/lib.rs index 3954223a489..e7e99318e2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -339,8 +339,6 @@ //! [`Ungil`]: crate::marker::Ungil pub use crate::class::*; pub use crate::conversion::{AsPyPointer, FromPyObject, IntoPyObject, IntoPyObjectExt}; -#[allow(deprecated)] -pub use crate::conversion::{IntoPy, ToPyObject}; pub use crate::err::{DowncastError, DowncastIntoError, PyErr, PyErrArguments, PyResult, ToPyErr}; #[cfg(not(any(PyPy, GraalPy)))] pub use crate::gil::{prepare_freethreaded_python, with_embedded_python_interpreter}; diff --git a/src/marker.rs b/src/marker.rs index 2ffd12f5995..a4a7be8c0c5 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -304,7 +304,7 @@ pub use nightly::Ungil; /// It serves three main purposes: /// - It provides a global API for the Python interpreter, such as [`Python::eval`]. /// - It can be passed to functions that require a proof of holding the GIL, such as -/// [`Py::clone_ref`][crate::Py::clone_ref]. +/// [`Py::clone_ref`](crate::Py::clone_ref). /// - Its lifetime represents the scope of holding the GIL which can be used to create Rust /// references that are bound to it, such as [`Bound<'py, PyAny>`]. /// @@ -974,8 +974,6 @@ mod tests { fn test_py_run_inserts_globals_2() { use std::ffi::CString; - use crate::Py; - #[crate::pyclass(crate = "crate")] #[derive(Clone)] struct CodeRunner { @@ -985,7 +983,7 @@ mod tests { impl CodeRunner { fn reproducer(&mut self, py: Python<'_>) -> PyResult<()> { let variables = PyDict::new(py); - variables.set_item("cls", Py::new(py, self.clone())?)?; + variables.set_item("cls", crate::Py::new(py, self.clone())?)?; py.run(self.code.as_c_str(), Some(&variables), None)?; Ok(()) diff --git a/src/prelude.rs b/src/prelude.rs index 62cde9a5591..258b522c103 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -9,8 +9,6 @@ //! ``` pub use crate::conversion::{FromPyObject, IntoPyObject}; -#[allow(deprecated)] -pub use crate::conversion::{IntoPy, ToPyObject}; pub use crate::err::{PyErr, PyResult}; pub use crate::instance::{Borrowed, Bound, Py, PyObject}; pub use crate::marker::Python; diff --git a/src/pybacked.rs b/src/pybacked.rs index 173d8e0e9e4..2d67786c802 100644 --- a/src/pybacked.rs +++ b/src/pybacked.rs @@ -9,8 +9,6 @@ use crate::{ }, Bound, DowncastError, FromPyObject, IntoPyObject, Py, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; /// A wrapper around `str` where the storage is owned by a Python `bytes` or `str` object. /// @@ -87,30 +85,6 @@ impl FromPyObject<'_> for PyBackedStr { } } -#[allow(deprecated)] -impl ToPyObject for PyBackedStr { - #[cfg(any(Py_3_10, not(Py_LIMITED_API)))] - fn to_object(&self, py: Python<'_>) -> Py { - self.storage.as_any().clone_ref(py) - } - #[cfg(not(any(Py_3_10, not(Py_LIMITED_API))))] - fn to_object(&self, py: Python<'_>) -> Py { - PyString::new(py, self).into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy> for PyBackedStr { - #[cfg(any(Py_3_10, not(Py_LIMITED_API)))] - fn into_py(self, _py: Python<'_>) -> Py { - self.storage.into_any() - } - #[cfg(not(any(Py_3_10, not(Py_LIMITED_API))))] - fn into_py(self, py: Python<'_>) -> Py { - PyString::new(py, &self).into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for PyBackedStr { type Target = PyAny; type Output = Bound<'py, Self::Target>; @@ -239,26 +213,6 @@ impl FromPyObject<'_> for PyBackedBytes { } } -#[allow(deprecated)] -impl ToPyObject for PyBackedBytes { - fn to_object(&self, py: Python<'_>) -> Py { - match &self.storage { - PyBackedBytesStorage::Python(bytes) => bytes.to_object(py), - PyBackedBytesStorage::Rust(bytes) => PyBytes::new(py, bytes).into_any().unbind(), - } - } -} - -#[allow(deprecated)] -impl IntoPy> for PyBackedBytes { - fn into_py(self, py: Python<'_>) -> Py { - match self.storage { - PyBackedBytesStorage::Python(bytes) => bytes.into_any(), - PyBackedBytesStorage::Rust(bytes) => PyBytes::new(py, &bytes).into_any().unbind(), - } - } -} - impl<'py> IntoPyObject<'py> for PyBackedBytes { type Target = PyBytes; type Output = Bound<'py, Self::Target>; @@ -404,19 +358,6 @@ mod test { }); } - #[test] - #[allow(deprecated)] - fn py_backed_str_into_py() { - Python::with_gil(|py| { - let orig_str = PyString::new(py, "hello"); - let py_backed_str = orig_str.extract::().unwrap(); - let new_str = py_backed_str.into_py(py); - assert_eq!(new_str.extract::(py).unwrap(), "hello"); - #[cfg(any(Py_3_10, not(Py_LIMITED_API)))] - assert!(new_str.is(&orig_str)); - }); - } - #[test] fn py_backed_bytes_empty() { Python::with_gil(|py| { @@ -454,7 +395,6 @@ mod test { } #[test] - #[allow(deprecated)] fn py_backed_bytes_into_pyobject() { Python::with_gil(|py| { let orig_bytes = PyBytes::new(py, b"abcde"); @@ -463,12 +403,10 @@ mod test { .into_pyobject(py) .unwrap() .is(&orig_bytes)); - assert!(py_backed_bytes.into_py(py).is(&orig_bytes)); }); } #[test] - #[allow(deprecated)] fn rust_backed_bytes_into_pyobject() { Python::with_gil(|py| { let orig_bytes = PyByteArray::new(py, b"abcde"); @@ -480,9 +418,6 @@ mod test { let to_object = (&rust_backed_bytes).into_pyobject(py).unwrap(); assert!(&to_object.is_exact_instance_of::()); assert_eq!(&to_object.extract::().unwrap(), b"abcde"); - let into_py = rust_backed_bytes.into_py(py).into_bound(py); - assert!(&into_py.is_exact_instance_of::()); - assert_eq!(&into_py.extract::().unwrap(), b"abcde"); }); } diff --git a/src/pycell.rs b/src/pycell.rs index 50a3e59ae15..1b7463a5941 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -199,9 +199,7 @@ use crate::ffi_ptr_ext::FfiPtrExt; use crate::internal_tricks::{ptr_from_mut, ptr_from_ref}; use crate::pyclass::{boolean_struct::False, PyClass}; use crate::types::any::PyAnyMethods; -#[allow(deprecated)] -use crate::IntoPy; -use crate::{ffi, Borrowed, Bound, PyErr, PyObject, Python}; +use crate::{ffi, Borrowed, Bound, PyErr, Python}; use std::convert::Infallible; use std::fmt; use std::mem::ManuallyDrop; @@ -449,20 +447,6 @@ impl Drop for PyRef<'_, T> { } } -#[allow(deprecated)] -impl IntoPy for PyRef<'_, T> { - fn into_py(self, py: Python<'_>) -> PyObject { - unsafe { PyObject::from_borrowed_ptr(py, self.inner.as_ptr()) } - } -} - -#[allow(deprecated)] -impl IntoPy for &'_ PyRef<'_, T> { - fn into_py(self, py: Python<'_>) -> PyObject { - unsafe { PyObject::from_borrowed_ptr(py, self.inner.as_ptr()) } - } -} - impl<'py, T: PyClass> IntoPyObject<'py> for PyRef<'py, T> { type Target = T; type Output = Bound<'py, T>; @@ -640,20 +624,6 @@ impl> Drop for PyRefMut<'_, T> { } } -#[allow(deprecated)] -impl> IntoPy for PyRefMut<'_, T> { - fn into_py(self, py: Python<'_>) -> PyObject { - unsafe { PyObject::from_borrowed_ptr(py, self.inner.as_ptr()) } - } -} - -#[allow(deprecated)] -impl> IntoPy for &'_ PyRefMut<'_, T> { - fn into_py(self, py: Python<'_>) -> PyObject { - self.inner.clone().into_py(py) - } -} - impl<'py, T: PyClass> IntoPyObject<'py> for PyRefMut<'py, T> { type Target = T; type Output = Bound<'py, T>; diff --git a/src/types/boolobject.rs b/src/types/boolobject.rs index 2e7f0369de1..5091930a6cb 100644 --- a/src/types/boolobject.rs +++ b/src/types/boolobject.rs @@ -2,14 +2,11 @@ use crate::inspect::types::TypeInfo; use crate::{ exceptions::PyTypeError, ffi, ffi_ptr_ext::FfiPtrExt, instance::Bound, - types::typeobject::PyTypeMethods, Borrowed, FromPyObject, PyAny, PyObject, PyResult, Python, + types::typeobject::PyTypeMethods, Borrowed, FromPyObject, PyAny, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use super::any::PyAnyMethods; use crate::conversion::IntoPyObject; -use crate::BoundObject; use std::convert::Infallible; /// Represents a Python `bool`. @@ -138,23 +135,6 @@ impl PartialEq> for &'_ bool { } } -/// Converts a Rust `bool` to a Python `bool`. -#[allow(deprecated)] -impl ToPyObject for bool { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for bool { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for bool { type Target = PyBool; type Output = Borrowed<'py, 'py, Self::Target>; diff --git a/src/types/float.rs b/src/types/float.rs index 89001495227..3753572904b 100644 --- a/src/types/float.rs +++ b/src/types/float.rs @@ -3,11 +3,9 @@ use crate::conversion::IntoPyObject; #[cfg(feature = "experimental-inspect")] use crate::inspect::types::TypeInfo; use crate::{ - ffi, ffi_ptr_ext::FfiPtrExt, instance::Bound, Borrowed, FromPyObject, PyAny, PyErr, PyObject, - PyResult, Python, + ffi, ffi_ptr_ext::FfiPtrExt, instance::Bound, Borrowed, FromPyObject, PyAny, PyErr, PyResult, + Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::convert::Infallible; use std::os::raw::c_double; @@ -20,7 +18,7 @@ use std::os::raw::c_double; /// [`Bound<'py, PyFloat>`][Bound]. /// /// You can usually avoid directly working with this type -/// by using [`ToPyObject`] and [`extract`][PyAnyMethods::extract] +/// by using [`IntoPyObject`] and [`extract`][PyAnyMethods::extract] /// with [`f32`]/[`f64`]. #[repr(transparent)] pub struct PyFloat(PyAny); @@ -71,22 +69,6 @@ impl<'py> PyFloatMethods<'py> for Bound<'py, PyFloat> { } } -#[allow(deprecated)] -impl ToPyObject for f64 { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for f64 { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for f64 { type Target = PyFloat; type Output = Bound<'py, Self::Target>; @@ -149,22 +131,6 @@ impl<'py> FromPyObject<'py> for f64 { } } -#[allow(deprecated)] -impl ToPyObject for f32 { - #[inline] - fn to_object(&self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy for f32 { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - self.into_pyobject(py).unwrap().into_any().unbind() - } -} - impl<'py> IntoPyObject<'py> for f32 { type Target = PyFloat; type Output = Bound<'py, Self::Target>; diff --git a/src/types/list.rs b/src/types/list.rs index 9612aa00cda..7c63c5bf44d 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -5,9 +5,7 @@ use crate::internal_tricks::get_ssize_index; use crate::types::any::PyAnyMethods; use crate::types::sequence::PySequenceMethods; use crate::types::{PySequence, PyTuple}; -use crate::{ - Borrowed, Bound, BoundObject, IntoPyObject, IntoPyObjectExt, PyAny, PyErr, PyObject, Python, -}; +use crate::{Borrowed, Bound, BoundObject, IntoPyObject, IntoPyObjectExt, PyAny, PyErr, Python}; use std::iter::FusedIterator; #[cfg(feature = "nightly")] use std::num::NonZero; @@ -24,15 +22,6 @@ pub struct PyList(PyAny); pyobject_native_type_core!(PyList, pyobject_native_static_type_object!(ffi::PyList_Type), #checkfunction=ffi::PyList_Check); -#[inline] -#[track_caller] -pub(crate) fn new_from_iter( - py: Python<'_>, - elements: impl ExactSizeIterator, -) -> Bound<'_, PyList> { - try_new_from_iter(py, elements.map(|e| e.into_bound(py)).map(Ok)).unwrap() -} - #[inline] #[track_caller] pub(crate) fn try_new_from_iter<'py>( diff --git a/src/types/none.rs b/src/types/none.rs index da8ef1aa51b..319a01a5311 100644 --- a/src/types/none.rs +++ b/src/types/none.rs @@ -1,7 +1,5 @@ use crate::ffi_ptr_ext::FfiPtrExt; -use crate::{ffi, types::any::PyAnyMethods, Borrowed, Bound, PyAny, PyObject, PyTypeInfo, Python}; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; +use crate::{ffi, types::any::PyAnyMethods, Borrowed, Bound, PyAny, PyTypeInfo, Python}; /// Represents the Python `None` object. /// @@ -41,27 +39,11 @@ unsafe impl PyTypeInfo for PyNone { } } -/// `()` is converted to Python `None`. -#[allow(deprecated)] -impl ToPyObject for () { - fn to_object(&self, py: Python<'_>) -> PyObject { - PyNone::get(py).into_py(py) - } -} - -#[allow(deprecated)] -impl IntoPy for () { - #[inline] - fn into_py(self, py: Python<'_>) -> PyObject { - PyNone::get(py).into_py(py) - } -} - #[cfg(test)] mod tests { use crate::types::any::PyAnyMethods; use crate::types::{PyDict, PyNone}; - use crate::{PyObject, PyTypeInfo, Python}; + use crate::{PyTypeInfo, Python}; #[test] fn test_none_is_itself() { @@ -85,25 +67,6 @@ mod tests { }) } - #[test] - #[allow(deprecated)] - fn test_unit_to_object_is_none() { - use crate::ToPyObject; - Python::with_gil(|py| { - assert!(().to_object(py).downcast_bound::(py).is_ok()); - }) - } - - #[test] - #[allow(deprecated)] - fn test_unit_into_py_is_none() { - use crate::IntoPy; - Python::with_gil(|py| { - let obj: PyObject = ().into_py(py); - assert!(obj.downcast_bound::(py).is_ok()); - }) - } - #[test] fn test_dict_is_not_none() { Python::with_gil(|py| { diff --git a/src/types/num.rs b/src/types/num.rs index 38874f29aba..79cd800b75d 100644 --- a/src/types/num.rs +++ b/src/types/num.rs @@ -7,9 +7,8 @@ use std::convert::Infallible; /// Values of this type are accessed via PyO3's smart pointers, e.g. as /// [`Py`][crate::Py] or [`Bound<'py, PyInt>`][crate::Bound]. /// -/// You can usually avoid directly working with this type -/// by using [`ToPyObject`](crate::conversion::ToPyObject) -/// and [`extract`](super::PyAnyMethods::extract) +/// You can usually avoid directly working with this type by using +/// [`IntoPyObject`] and [`extract`](super::PyAnyMethods::extract) /// with the primitive Rust integer types. #[repr(transparent)] pub struct PyInt(PyAny); diff --git a/src/types/set.rs b/src/types/set.rs index 93c251d460f..8db32c56c1e 100644 --- a/src/types/set.rs +++ b/src/types/set.rs @@ -1,6 +1,4 @@ use crate::types::PyIterator; -#[allow(deprecated)] -use crate::ToPyObject; use crate::{ err::{self, PyErr, PyResult}, ffi_ptr_ext::FfiPtrExt, @@ -265,16 +263,6 @@ impl ExactSizeIterator for BoundSetIterator<'_> { } } -#[allow(deprecated)] -#[inline] -pub(crate) fn new_from_iter( - py: Python<'_>, - elements: impl IntoIterator, -) -> PyResult> { - let mut iter = elements.into_iter().map(|e| e.to_object(py)); - try_new_from_iter(py, &mut iter) -} - #[inline] pub(crate) fn try_new_from_iter<'py, T>( py: Python<'py>, diff --git a/src/types/slice.rs b/src/types/slice.rs index b74a228aae3..97c38e0f36c 100644 --- a/src/types/slice.rs +++ b/src/types/slice.rs @@ -2,9 +2,7 @@ use crate::err::{PyErr, PyResult}; use crate::ffi; use crate::ffi_ptr_ext::FfiPtrExt; use crate::types::any::PyAnyMethods; -#[allow(deprecated)] -use crate::ToPyObject; -use crate::{Bound, IntoPyObject, PyAny, PyObject, Python}; +use crate::{Bound, IntoPyObject, PyAny, Python}; use std::convert::Infallible; /// Represents a Python `slice`. @@ -122,13 +120,6 @@ impl<'py> PySliceMethods<'py> for Bound<'py, PySlice> { } } -#[allow(deprecated)] -impl ToPyObject for PySliceIndices { - fn to_object(&self, py: Python<'_>) -> PyObject { - PySlice::new(py, self.start, self.stop, self.step).into() - } -} - impl<'py> IntoPyObject<'py> for PySliceIndices { type Target = PySlice; type Output = Bound<'py, Self::Target>; diff --git a/src/types/string.rs b/src/types/string.rs index f7a724b9fce..a9df79c305d 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -6,8 +6,6 @@ use crate::py_result_ext::PyResultExt; use crate::types::any::PyAnyMethods; use crate::types::bytes::PyBytesMethods; use crate::types::PyBytes; -#[allow(deprecated)] -use crate::IntoPy; use crate::{ffi, Bound, Py, PyAny, PyResult, Python}; use std::borrow::Cow; use std::ffi::CString; @@ -422,27 +420,6 @@ impl Py { } } -#[allow(deprecated)] -impl IntoPy> for Bound<'_, PyString> { - fn into_py(self, _py: Python<'_>) -> Py { - self.unbind() - } -} - -#[allow(deprecated)] -impl IntoPy> for &Bound<'_, PyString> { - fn into_py(self, _py: Python<'_>) -> Py { - self.clone().unbind() - } -} - -#[allow(deprecated)] -impl IntoPy> for &'_ Py { - fn into_py(self, py: Python<'_>) -> Py { - self.clone_ref(py) - } -} - /// Compares whether the data in the Python string is equal to the given UTF8. /// /// In some cases Python equality might be more appropriate; see the note on [`PyString`]. diff --git a/src/types/tuple.rs b/src/types/tuple.rs index c412a81a752..0a315a42e00 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -6,11 +6,8 @@ use crate::instance::Borrowed; use crate::internal_tricks::get_ssize_index; use crate::types::{any::PyAnyMethods, sequence::PySequenceMethods, PyList, PySequence}; use crate::{ - exceptions, Bound, FromPyObject, IntoPyObject, IntoPyObjectExt, Py, PyAny, PyErr, PyObject, - PyResult, Python, + exceptions, Bound, FromPyObject, IntoPyObject, IntoPyObjectExt, PyAny, PyErr, PyResult, Python, }; -#[allow(deprecated)] -use crate::{IntoPy, ToPyObject}; use std::iter::FusedIterator; #[cfg(feature = "nightly")] use std::num::NonZero; @@ -582,20 +579,6 @@ impl ExactSizeIterator for BorrowedTupleIterator<'_, '_> { impl FusedIterator for BorrowedTupleIterator<'_, '_> {} -#[allow(deprecated)] -impl IntoPy> for Bound<'_, PyTuple> { - fn into_py(self, _: Python<'_>) -> Py { - self.unbind() - } -} - -#[allow(deprecated)] -impl IntoPy> for &'_ Bound<'_, PyTuple> { - fn into_py(self, _: Python<'_>) -> Py { - self.clone().unbind() - } -} - #[cold] fn wrong_tuple_length(t: &Bound<'_, PyTuple>, expected_length: usize) -> PyErr { let msg = format!( @@ -607,20 +590,6 @@ fn wrong_tuple_length(t: &Bound<'_, PyTuple>, expected_length: usize) -> PyErr { } macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+} => { - #[allow(deprecated)] - impl <$($T: ToPyObject),+> ToPyObject for ($($T,)+) { - fn to_object(&self, py: Python<'_>) -> PyObject { - array_into_tuple(py, [$(self.$n.to_object(py).into_bound(py)),+]).into() - } - } - - #[allow(deprecated)] - impl <$($T: IntoPy),+> IntoPy for ($($T,)+) { - fn into_py(self, py: Python<'_>) -> PyObject { - array_into_tuple(py, [$(self.$n.into_py(py).into_bound(py)),+]).into() - } - } - impl <'py, $($T),+> IntoPyObject<'py> for ($($T,)+) where $($T: IntoPyObject<'py>,)+ @@ -916,13 +885,6 @@ macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+ } } - #[allow(deprecated)] - impl <$($T: IntoPy),+> IntoPy> for ($($T,)+) { - fn into_py(self, py: Python<'_>) -> Py { - array_into_tuple(py, [$(self.$n.into_py(py).into_bound(py)),+]).unbind() - } - } - impl<'py, $($T: FromPyObject<'py>),+> FromPyObject<'py> for ($($T,)+) { fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult { diff --git a/tests/ui/invalid_property_args.stderr b/tests/ui/invalid_property_args.stderr index 5ef01fa210a..047e6709c21 100644 --- a/tests/ui/invalid_property_args.stderr +++ b/tests/ui/invalid_property_args.stderr @@ -65,11 +65,11 @@ error[E0277]: `PhantomData` cannot be converted to a Python object &'a (T0, T1, T2, T3, T4) and $N others = note: required for `PhantomData` to implement `for<'py> PyO3GetField<'py>` -note: required by a bound in `PyClassGetterGenerator::::generate` +note: required by a bound in `PyClassGetterGenerator::::generate` --> src/impl_/pyclass.rs | - | pub const fn generate(&self, _name: &'static CStr, _doc: &'static CStr) -> PyMethodDefType + | pub const fn generate(&self, name: &'static CStr, doc: &'static CStr) -> PyMethodDefType | -------- required by a bound in this associated function ... | for<'py> FieldT: PyO3GetField<'py>, - | ^^^^^^^^^^^^^^^^^ required by this bound in `PyClassGetterGenerator::::generate` + | ^^^^^^^^^^^^^^^^^ required by this bound in `PyClassGetterGenerator::::generate`