Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ documentation = "https://docs.rs/crate/pythonize/"

[dependencies]
serde = { version = "1.0", default-features = false, features = ["std"] }
pyo3 = { version = "0.26", default-features = false }
pyo3 = { version = "0.27", default-features = false }

[dev-dependencies]
serde = { version = "1.0", default-features = false, features = ["derive"] }
pyo3 = { version = "0.26", default-features = false, features = ["auto-initialize", "macros", "py-clone"] }
pyo3 = { version = "0.27", default-features = false, features = ["auto-initialize", "macros", "py-clone"] }
serde_json = "1.0"
serde_bytes = "0.11"
maplit = "1.0.2"
Expand Down
14 changes: 7 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pyo3::PyErr;
use pyo3::{exceptions::*, DowncastError, DowncastIntoError};
use pyo3::{exceptions::*, CastError, CastIntoError};
use serde::{de, ser};
use std::convert::Infallible;
use std::error;
Expand Down Expand Up @@ -153,18 +153,18 @@ impl From<PyErr> for PythonizeError {
}
}

/// Handle errors that occur when attempting to use `PyAny::cast_as`
impl<'a, 'py> From<DowncastError<'a, 'py>> for PythonizeError {
fn from(other: DowncastError<'a, 'py>) -> Self {
/// Handle errors that occur when attempting to use `PyAny::cast`
impl<'a, 'py> From<CastError<'a, 'py>> for PythonizeError {
fn from(other: CastError<'a, 'py>) -> Self {
Self {
inner: Box::new(ErrorImpl::UnexpectedType(other.to_string())),
}
}
}

/// Handle errors that occur when attempting to use `PyAny::cast_as`
impl<'py> From<DowncastIntoError<'py>> for PythonizeError {
fn from(other: DowncastIntoError<'py>) -> Self {
/// Handle errors that occur when attempting to use `PyAny::cast`
impl<'py> From<CastIntoError<'py>> for PythonizeError {
fn from(other: CastIntoError<'py>) -> Self {
Self {
inner: Box::new(ErrorImpl::UnexpectedType(other.to_string())),
}
Expand Down
11 changes: 7 additions & 4 deletions tests/test_with_serde_path_to_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ fn test_de_invalid() {
let err = serde_path_to_error::deserialize::<_, Root<String>>(de).unwrap_err();

assert_eq!(err.path().to_string(), "root_map.nested_1.nested_key");
assert_eq!(err.to_string(), "root_map.nested_1.nested_key: unexpected type: 'int' object cannot be converted to 'PyString'");
assert_eq!(
err.to_string(),
"root_map.nested_1.nested_key: unexpected type: 'int' object cannot be cast as 'str'"
);
})
}

Expand Down Expand Up @@ -143,15 +146,15 @@ fn test_ser_valid() {
.get_item("root_map")
.unwrap()
.unwrap()
.downcast_into::<PyDict>()
.cast_into::<PyDict>()
.unwrap();
assert_eq!(root_map.len(), 2);

let nested_0 = root_map
.get_item("nested_0")
.unwrap()
.unwrap()
.downcast_into::<PyDict>()
.cast_into::<PyDict>()
.unwrap();
assert_eq!(nested_0.len(), 1);
let nested_key_0: String = nested_0
Expand All @@ -166,7 +169,7 @@ fn test_ser_valid() {
.get_item("nested_1")
.unwrap()
.unwrap()
.downcast_into::<PyDict>()
.cast_into::<PyDict>()
.unwrap();
assert_eq!(nested_1.len(), 1);
let nested_key_1: String = nested_1
Expand Down
Loading