diff --git a/guide/src/migration.md b/guide/src/migration.md index aeb7dcd0c2d..ba20f39c3db 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -155,6 +155,9 @@ Notable features of this new trait: All PyO3 provided types as well as `#[pyclass]`es already implement `IntoPyObject`. Other types will need to adapt an implementation of `IntoPyObject` to stay compatible with the Python APIs. +Together with the introduction of `IntoPyObject` the old conversion traits `ToPyObject` and `IntoPy` +are deprecated and will be removed in a future PyO3 version. + Before: ```rust,ignore diff --git a/src/conversion.rs b/src/conversion.rs index 8847e377d9d..4e0de44b4a1 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -66,7 +66,7 @@ pub unsafe trait AsPyPointer { /// 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 for more information." + note = "`ToPyObject` is going to be replaced by `IntoPyObject`. See the migration guide (https://pyo3.rs/v0.23/migration) for more information." )] pub trait ToPyObject { /// Converts self into a Python object. diff --git a/src/conversions/chrono.rs b/src/conversions/chrono.rs index a4cfd89b8e0..ce94b98c1a3 100644 --- a/src/conversions/chrono.rs +++ b/src/conversions/chrono.rs @@ -20,7 +20,7 @@ //! //! ```rust //! use chrono::{DateTime, Duration, TimeZone, Utc}; -//! use pyo3::{Python, PyResult, conversion::IntoPyObject, types::PyAnyMethods}; +//! use pyo3::{Python, PyResult, IntoPyObject, types::PyAnyMethods}; //! //! fn main() -> PyResult<()> { //! pyo3::prepare_freethreaded_python(); diff --git a/src/conversions/chrono_tz.rs b/src/conversions/chrono_tz.rs index 2dc68218f06..ff014eb99d9 100644 --- a/src/conversions/chrono_tz.rs +++ b/src/conversions/chrono_tz.rs @@ -21,7 +21,7 @@ //! //! ```rust,no_run //! use chrono_tz::Tz; -//! use pyo3::{Python, PyResult, conversion::IntoPyObject, types::PyAnyMethods}; +//! use pyo3::{Python, PyResult, IntoPyObject, types::PyAnyMethods}; //! //! fn main() -> PyResult<()> { //! pyo3::prepare_freethreaded_python(); diff --git a/src/conversions/either.rs b/src/conversions/either.rs index ec0b7e49d96..2cf1029ffb6 100644 --- a/src/conversions/either.rs +++ b/src/conversions/either.rs @@ -26,7 +26,7 @@ //! //! ```rust //! use either::Either; -//! use pyo3::{Python, PyResult, conversion::IntoPyObject, types::PyAnyMethods}; +//! use pyo3::{Python, PyResult, IntoPyObject, types::PyAnyMethods}; //! //! fn main() -> PyResult<()> { //! pyo3::prepare_freethreaded_python(); @@ -172,9 +172,8 @@ mod tests { use std::borrow::Cow; use crate::exceptions::PyTypeError; - use crate::Python; + use crate::{IntoPyObject, Python}; - use crate::prelude::IntoPyObject; use crate::types::PyAnyMethods; use either::Either; diff --git a/src/conversions/indexmap.rs b/src/conversions/indexmap.rs index 638d303e37a..8d74b126f29 100644 --- a/src/conversions/indexmap.rs +++ b/src/conversions/indexmap.rs @@ -182,9 +182,8 @@ where #[cfg(test)] mod test_indexmap { - use crate::prelude::IntoPyObject; use crate::types::*; - use crate::{IntoPy, PyObject, Python}; + use crate::{IntoPy, IntoPyObject, PyObject, Python}; #[test] fn test_indexmap_indexmap_to_python() { diff --git a/src/conversions/num_complex.rs b/src/conversions/num_complex.rs index 58dc65df32e..4b3be8e15b0 100644 --- a/src/conversions/num_complex.rs +++ b/src/conversions/num_complex.rs @@ -219,9 +219,9 @@ complex_conversion!(f64); #[cfg(test)] mod tests { use super::*; - use crate::prelude::IntoPyObject; use crate::tests::common::generate_unique_module_name; use crate::types::{complex::PyComplexMethods, PyModule}; + use crate::IntoPyObject; use pyo3_ffi::c_str; #[test] diff --git a/src/conversions/std/num.rs b/src/conversions/std/num.rs index 043c2040c5b..e7b8addac82 100644 --- a/src/conversions/std/num.rs +++ b/src/conversions/std/num.rs @@ -845,9 +845,8 @@ mod test_128bit_integers { #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; use crate::types::PyAnyMethods; - use crate::Python; + use crate::{IntoPyObject, Python}; use std::num::*; #[test] diff --git a/src/conversions/std/osstr.rs b/src/conversions/std/osstr.rs index 93669311de6..14c5902d8d9 100644 --- a/src/conversions/std/osstr.rs +++ b/src/conversions/std/osstr.rs @@ -224,10 +224,8 @@ impl<'py> IntoPyObject<'py> for &OsString { #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; - use crate::types::{PyAnyMethods, PyStringMethods}; - use crate::BoundObject; - use crate::{types::PyString, IntoPy, PyObject, Python}; + use crate::types::{PyAnyMethods, PyString, PyStringMethods}; + use crate::{BoundObject, IntoPy, IntoPyObject, PyObject, Python}; use std::fmt::Debug; use std::{ borrow::Cow, diff --git a/src/conversions/std/path.rs b/src/conversions/std/path.rs index 7ef5f4af47d..d1b628b065e 100644 --- a/src/conversions/std/path.rs +++ b/src/conversions/std/path.rs @@ -141,10 +141,8 @@ impl<'py> IntoPyObject<'py> for &PathBuf { #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; - use crate::types::{PyAnyMethods, PyStringMethods}; - use crate::BoundObject; - use crate::{types::PyString, IntoPy, PyObject, Python}; + use crate::types::{PyAnyMethods, PyString, PyStringMethods}; + use crate::{BoundObject, IntoPy, IntoPyObject, PyObject, Python}; use std::borrow::Cow; use std::fmt::Debug; use std::path::{Path, PathBuf}; diff --git a/src/conversions/std/set.rs b/src/conversions/std/set.rs index b290423fe49..ff5ab572bb5 100644 --- a/src/conversions/std/set.rs +++ b/src/conversions/std/set.rs @@ -177,9 +177,8 @@ where #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; use crate::types::{any::PyAnyMethods, PyFrozenSet, PySet}; - use crate::{IntoPy, PyObject, Python}; + use crate::{IntoPy, IntoPyObject, PyObject, Python}; use std::collections::{BTreeSet, HashSet}; #[test] diff --git a/src/conversions/std/string.rs b/src/conversions/std/string.rs index 47eee5c2d13..667edaaeb5f 100644 --- a/src/conversions/std/string.rs +++ b/src/conversions/std/string.rs @@ -265,10 +265,8 @@ impl FromPyObject<'_> for char { #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; use crate::types::any::PyAnyMethods; - use crate::Python; - use crate::{IntoPy, PyObject}; + use crate::{IntoPy, IntoPyObject, PyObject, Python}; use std::borrow::Cow; #[test] diff --git a/src/instance.rs b/src/instance.rs index 68193bb0cb3..a86bed94513 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1965,8 +1965,7 @@ impl PyObject { #[cfg(test)] mod tests { - use super::{Bound, Py, PyObject}; - use crate::prelude::IntoPyObject; + use super::{Bound, IntoPyObject, Py, PyObject}; use crate::tests::common::generate_unique_module_name; use crate::types::{dict::IntoPyDict, PyAnyMethods, PyCapsule, PyDict, PyString}; use crate::{ffi, Borrowed, PyAny, PyResult, Python}; diff --git a/src/lib.rs b/src/lib.rs index c1e8cfde16d..2cb189fb489 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -322,7 +322,7 @@ pub use crate::class::*; #[allow(deprecated)] pub use crate::conversion::ToPyObject; -pub use crate::conversion::{AsPyPointer, FromPyObject, IntoPy}; +pub use crate::conversion::{AsPyPointer, FromPyObject, IntoPy, IntoPyObject}; 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/pybacked.rs b/src/pybacked.rs index c27383ba9bc..5a45c8f1036 100644 --- a/src/pybacked.rs +++ b/src/pybacked.rs @@ -5,12 +5,11 @@ use std::{convert::Infallible, ops::Deref, ptr::NonNull, sync::Arc}; #[allow(deprecated)] use crate::ToPyObject; use crate::{ - prelude::IntoPyObject, types::{ any::PyAnyMethods, bytearray::PyByteArrayMethods, bytes::PyBytesMethods, string::PyStringMethods, PyByteArray, PyBytes, PyString, }, - Bound, DowncastError, FromPyObject, IntoPy, Py, PyAny, PyErr, PyResult, Python, + Bound, DowncastError, FromPyObject, IntoPy, IntoPyObject, Py, PyAny, PyErr, PyResult, Python, }; /// A wrapper around `str` where the storage is owned by a Python `bytes` or `str` object. @@ -360,8 +359,7 @@ use impl_traits; #[cfg(test)] mod test { use super::*; - use crate::prelude::IntoPyObject; - use crate::Python; + use crate::{IntoPyObject, Python}; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/src/types/any.rs b/src/types/any.rs index f75cfdf1b78..47cebb0363b 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -1637,10 +1637,9 @@ mod tests { use crate::{ basic::CompareOp, ffi, - prelude::IntoPyObject, tests::common::generate_unique_module_name, types::{IntoPyDict, PyAny, PyAnyMethods, PyBool, PyInt, PyList, PyModule, PyTypeMethods}, - Bound, BoundObject, PyTypeInfo, Python, + Bound, BoundObject, IntoPyObject, PyTypeInfo, Python, }; use pyo3_ffi::c_str; use std::fmt::Debug; diff --git a/src/types/boolobject.rs b/src/types/boolobject.rs index 526f68044a4..6f90329900d 100644 --- a/src/types/boolobject.rs +++ b/src/types/boolobject.rs @@ -254,10 +254,10 @@ impl FromPyObject<'_> for bool { #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; use crate::types::any::PyAnyMethods; use crate::types::boolobject::PyBoolMethods; use crate::types::PyBool; + use crate::IntoPyObject; use crate::Python; #[test] diff --git a/src/types/dict.rs b/src/types/dict.rs index 35cf8569248..9b7d8697d20 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -6,7 +6,7 @@ use crate::instance::{Borrowed, Bound}; use crate::py_result_ext::PyResultExt; use crate::types::any::PyAnyMethods; use crate::types::{PyAny, PyList}; -use crate::{ffi, BoundObject, Python}; +use crate::{ffi, BoundObject, IntoPyObject, Python}; /// Represents a Python `dict`. /// @@ -558,7 +558,6 @@ mod borrowed_iter { } } -use crate::prelude::IntoPyObject; pub(crate) use borrowed_iter::BorrowedDictIter; /// Conversion trait that allows a sequence of tuples to be converted into `PyDict` diff --git a/src/types/iterator.rs b/src/types/iterator.rs index fe3eb9ed636..068ab1fce34 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -107,9 +107,8 @@ impl PyTypeCheck for PyIterator { mod tests { use super::PyIterator; use crate::exceptions::PyTypeError; - use crate::prelude::IntoPyObject; use crate::types::{PyAnyMethods, PyDict, PyList, PyListMethods}; - use crate::{ffi, Python}; + use crate::{ffi, IntoPyObject, Python}; #[test] fn vec_iter() { diff --git a/src/types/list.rs b/src/types/list.rs index dc236c12a4a..114bcad7d31 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -5,9 +5,8 @@ use crate::ffi::{self, Py_ssize_t}; use crate::ffi_ptr_ext::FfiPtrExt; use crate::internal_tricks::get_ssize_index; use crate::types::{PySequence, PyTuple}; -use crate::{Borrowed, Bound, BoundObject, PyAny, PyObject, Python}; +use crate::{Borrowed, Bound, BoundObject, IntoPyObject, PyAny, PyObject, Python}; -use crate::prelude::IntoPyObject; use crate::types::any::PyAnyMethods; use crate::types::sequence::PySequenceMethods; @@ -575,7 +574,7 @@ mod tests { use crate::types::list::PyListMethods; use crate::types::sequence::PySequenceMethods; use crate::types::{PyList, PyTuple}; - use crate::{ffi, Python}; + use crate::{ffi, Python, IntoPyObject}; #[test] fn test_new() { @@ -979,7 +978,6 @@ mod tests { }); } - use crate::prelude::IntoPyObject; use std::ops::Range; // An iterator that lies about its `ExactSizeIterator` implementation. diff --git a/src/types/sequence.rs b/src/types/sequence.rs index d427edbae5a..0801704f700 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -5,12 +5,11 @@ use crate::ffi_ptr_ext::FfiPtrExt; use crate::inspect::types::TypeInfo; use crate::instance::Bound; use crate::internal_tricks::get_ssize_index; -use crate::prelude::IntoPyObject; use crate::py_result_ext::PyResultExt; use crate::sync::GILOnceCell; use crate::type_object::PyTypeInfo; use crate::types::{any::PyAnyMethods, PyAny, PyList, PyString, PyTuple, PyType}; -use crate::{ffi, Borrowed, BoundObject, FromPyObject, Py, PyTypeCheck, Python}; +use crate::{ffi, Borrowed, BoundObject, FromPyObject, IntoPyObject, Py, PyTypeCheck, Python}; /// Represents a reference to a Python object supporting the sequence protocol. /// @@ -408,9 +407,8 @@ impl PyTypeCheck for PySequence { #[cfg(test)] mod tests { - use crate::prelude::IntoPyObject; use crate::types::{PyAnyMethods, PyList, PySequence, PySequenceMethods, PyTuple}; - use crate::{ffi, PyObject, Python}; + use crate::{ffi, IntoPyObject, PyObject, Python}; fn get_object() -> PyObject { // Convenience function for getting a single unique object diff --git a/src/types/slice.rs b/src/types/slice.rs index 5ac59c33e68..9ca2aa4ec43 100644 --- a/src/types/slice.rs +++ b/src/types/slice.rs @@ -1,11 +1,10 @@ use crate::err::{PyErr, PyResult}; use crate::ffi; use crate::ffi_ptr_ext::FfiPtrExt; -use crate::prelude::IntoPyObject; use crate::types::any::PyAnyMethods; #[allow(deprecated)] use crate::ToPyObject; -use crate::{Bound, PyAny, PyObject, Python}; +use crate::{Bound, IntoPyObject, PyAny, PyObject, Python}; use std::convert::Infallible; /// Represents a Python `slice`. diff --git a/src/types/string.rs b/src/types/string.rs index 76c3eda03f2..1bcd025d1ce 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -577,8 +577,7 @@ impl PartialEq> for &'_ str { #[cfg(test)] mod tests { use super::*; - use crate::prelude::IntoPyObject; - use crate::PyObject; + use crate::{IntoPyObject, PyObject}; #[test] fn test_to_cow_utf8() { diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 1c93d5a6bf5..02a77578386 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -821,8 +821,9 @@ tuple_conversion!( #[cfg(test)] mod tests { use crate::types::{any::PyAnyMethods, tuple::PyTupleMethods, PyList, PyTuple}; - use crate::Python; + use crate::{Python, IntoPyObject}; use std::collections::HashSet; + use std::ops::Range; #[test] fn test_new() { @@ -1142,9 +1143,6 @@ mod tests { }); } - use crate::prelude::IntoPyObject; - use std::ops::Range; - // An iterator that lies about its `ExactSizeIterator` implementation. // See https://github.com/PyO3/pyo3/issues/2118 struct FaultyIter(Range, usize); diff --git a/src/types/weakref/proxy.rs b/src/types/weakref/proxy.rs index 6eb188b1b86..bf9d69295d2 100644 --- a/src/types/weakref/proxy.rs +++ b/src/types/weakref/proxy.rs @@ -1,10 +1,9 @@ use crate::err::PyResult; use crate::ffi_ptr_ext::FfiPtrExt; -use crate::prelude::IntoPyObject; use crate::py_result_ext::PyResultExt; use crate::type_object::PyTypeCheck; use crate::types::{any::PyAny, PyNone}; -use crate::{ffi, Bound, BoundObject}; +use crate::{ffi, Bound, BoundObject, IntoPyObject}; use super::PyWeakrefMethods; diff --git a/src/types/weakref/reference.rs b/src/types/weakref/reference.rs index 8ca257f0145..f26df4953ea 100644 --- a/src/types/weakref/reference.rs +++ b/src/types/weakref/reference.rs @@ -1,9 +1,8 @@ use crate::err::PyResult; use crate::ffi_ptr_ext::FfiPtrExt; -use crate::prelude::IntoPyObject; use crate::py_result_ext::PyResultExt; use crate::types::{any::PyAny, PyNone}; -use crate::{ffi, Bound, BoundObject}; +use crate::{ffi, Bound, BoundObject, IntoPyObject}; #[cfg(any(PyPy, GraalPy, Py_LIMITED_API))] use crate::type_object::PyTypeCheck;