Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed Oct 4, 2024
1 parent 5d4c362 commit af09744
Show file tree
Hide file tree
Showing 26 changed files with 34 additions and 57 deletions.
3 changes: 3 additions & 0 deletions guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/chrono_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/conversions/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/conversions/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/num_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/conversions/std/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions src/conversions/std/osstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions src/conversions/std/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions src/conversions/std/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions src/conversions/std/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,8 +1943,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};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 2 additions & 4 deletions src/pybacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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};

Expand Down
3 changes: 1 addition & 2 deletions src/types/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,10 +1606,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;
Expand Down
2 changes: 1 addition & 1 deletion src/types/boolobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions src/types/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -554,7 +554,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`
Expand Down
3 changes: 1 addition & 2 deletions src/types/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 1 addition & 3 deletions src/types/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -979,7 +978,6 @@ mod tests {
});
}

use crate::prelude::IntoPyObject;
use std::ops::Range;

// An iterator that lies about its `ExactSizeIterator` implementation.
Expand Down
6 changes: 2 additions & 4 deletions src/types/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/types/slice.rs
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
3 changes: 1 addition & 2 deletions src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,7 @@ impl PartialEq<Borrowed<'_, '_, PyString>> 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() {
Expand Down
6 changes: 2 additions & 4 deletions src/types/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,10 @@ tuple_conversion!(

#[cfg(test)]
mod tests {
use crate::types::{any::PyAnyMethods, tuple::PyTupleMethods, PyList, PyTuple};
use crate::types::{any::PyAnyMethods, tuple::PyTupleMethods, IntoPyObject, PyList, PyTuple};
use crate::Python;
use std::collections::HashSet;
use std::ops::Range;

#[test]
fn test_new() {
Expand Down Expand Up @@ -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>, usize);
Expand Down
3 changes: 1 addition & 2 deletions src/types/weakref/proxy.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/types/weakref/reference.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit af09744

Please sign in to comment.