Skip to content

Commit 6c2c3f2

Browse files
authored
Merge pull request #66 from HenningHolmDE/update_to_pyo3_0.22
Update to PyO3 0.22
2 parents 30ce873 + e7cf258 commit 6c2c3f2

File tree

9 files changed

+126
-121
lines changed

9 files changed

+126
-121
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
include:
4848
- python-version: "3.12"
4949
os: "ubuntu-latest"
50-
rust: "1.56"
50+
rust: "1.63"
5151
- python-version: "3.12"
5252
python-architecture: "arm64"
5353
os: "macos-latest"

CHANGELOG.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
## Unreleased
22

3+
- Bump MSRV to 1.63
4+
- Update to PyO3 0.22
35
- Support `u128` / `i128` integers.
6+
- Remove support for PyO3's `gil-refs` feature
7+
- `pythonize()` now returns `Bound<'py, PyAny>` instead of `Py<PyAny>`
8+
- `depythonize()` now take a `&Bound` and is no longer deprecated
9+
- `depythonize_bound()` is now deprecated
10+
- `Depythonizer` now contains a `&Bound` and so has an extra lifetime `'bound`
11+
- `Depythonizer::from_object()` now takes a `&Bound` and is no longer deprecated
412
- Fix overflow error attempting to depythonize `u64` values greater than `i64::MAX` to types like `serde_json::Value`
5-
- `depythonize()` now take a `&Bound` and is no longer depreciate
6-
- `depythonize_object()` replace the old `depythonize()` and is depreciated
7-
- `depythonize_bound()` is depreciated
8-
- `Depythonizer` now need a `&Bound` and so have extra lifetime `'bound`
9-
- `Depythonizer::from_object()` now take a `&Bound` and is no longer depreciate
10-
- `Depythonizer::from_object_bound()` can't be implemented so have been removed
1113

1214
## 0.21.1 - 2024-04-02
1315

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "pythonize"
33
version = "0.21.1"
44
authors = ["David Hewitt <1939362+davidhewitt@users.noreply.github.com>"]
55
edition = "2021"
6-
rust-version = "1.56"
6+
rust-version = "1.63"
77
license = "MIT"
88
description = "Serde Serializer & Deserializer from Rust <--> Python, backed by PyO3."
99
homepage = "https://github.com/davidhewitt/pythonize"
@@ -13,11 +13,12 @@ documentation = "https://docs.rs/crate/pythonize/"
1313

1414
[dependencies]
1515
serde = { version = "1.0", default-features = false, features = ["std"] }
16-
pyo3 = { version = "0.21.0", default-features = false }
16+
pyo3 = { version = "0.22.0", default-features = false }
1717

1818
[dev-dependencies]
1919
serde = { version = "1.0", default-features = false, features = ["derive"] }
20-
pyo3 = { version = "0.21.1", default-features = false, features = ["auto-initialize", "macros"] }
20+
pyo3 = { version = "0.22.0", default-features = false, features = ["auto-initialize", "macros", "py-clone"] }
2121
serde_json = "1.0"
22+
serde_bytes = "0.11"
2223
maplit = "1.0.2"
2324
serde_path_to_error = "0.1.15"

src/de.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pyo3::{types::*, Bound, PyNativeType};
1+
use pyo3::{types::*, Bound};
22
use serde::de::{self, IntoDeserializer};
33
use serde::Deserialize;
44

@@ -14,10 +14,7 @@ where
1414
}
1515

1616
/// Attempt to convert a Python object to an instance of `T`
17-
#[deprecated(
18-
since = "0.21.1",
19-
note = "will be replaced by `depythonize` in a future release"
20-
)]
17+
#[deprecated(since = "0.22.0", note = "use `depythonize` instead")]
2118
pub fn depythonize_bound<'py, T>(obj: Bound<'py, PyAny>) -> Result<T>
2219
where
2320
T: for<'a> Deserialize<'a>,
@@ -26,30 +23,14 @@ where
2623
T::deserialize(&mut depythonizer)
2724
}
2825

29-
/// Attempt to convert a Python object to an instance of `T`
30-
#[deprecated(
31-
since = "0.21.1",
32-
note = "will be replaced by `depythonize` in a future release"
33-
)]
34-
pub fn depythonize_object<'de, T>(obj: &'de PyAny) -> Result<T>
35-
where
36-
T: Deserialize<'de>,
37-
{
38-
let obj = obj.as_borrowed().to_owned();
39-
let mut depythonizer = Depythonizer::from_object(&obj);
40-
T::deserialize(&mut depythonizer)
41-
}
42-
4326
/// A structure that deserializes Python objects into Rust values
4427
pub struct Depythonizer<'py, 'bound> {
4528
input: &'bound Bound<'py, PyAny>,
4629
}
4730

4831
impl<'py, 'bound> Depythonizer<'py, 'bound> {
4932
/// Create a deserializer from a Python object
50-
pub fn from_object<'input, 'gil>(
51-
input: &'input Bound<'gil, PyAny>,
52-
) -> Depythonizer<'gil, 'input> {
33+
pub fn from_object<'input>(input: &'input Bound<'py, PyAny>) -> Depythonizer<'py, 'input> {
5334
Depythonizer { input }
5435
}
5536

src/error.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use pyo3::PyErr;
12
use pyo3::{exceptions::*, DowncastError, DowncastIntoError};
2-
use pyo3::{PyDowncastError, PyErr};
33
use serde::{de, ser};
44
use std::error;
55
use std::fmt::{self, Debug, Display};
@@ -145,15 +145,6 @@ impl From<PyErr> for PythonizeError {
145145
}
146146
}
147147

148-
/// Handle errors that occur when attempting to use `PyAny::cast_as`
149-
impl<'a> From<PyDowncastError<'a>> for PythonizeError {
150-
fn from(other: PyDowncastError) -> Self {
151-
Self {
152-
inner: Box::new(ErrorImpl::UnexpectedType(other.to_string())),
153-
}
154-
}
155-
}
156-
157148
/// Handle errors that occur when attempting to use `PyAny::cast_as`
158149
impl<'a, 'py> From<DowncastError<'a, 'py>> for PythonizeError {
159150
fn from(other: DowncastError<'a, 'py>) -> Self {

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! # Examples
1010
//! ```
1111
//! use serde::{Serialize, Deserialize};
12-
//! use pyo3::Python;
12+
//! use pyo3::{types::PyAnyMethods, Python};
1313
//! use pythonize::{depythonize, pythonize};
1414
//!
1515
//! #[derive(Debug, Serialize, Deserialize, PartialEq)]
@@ -27,10 +27,10 @@
2727
//! // Rust -> Python
2828
//! let obj = pythonize(py, &sample).unwrap();
2929
//!
30-
//! assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.as_ref(py).repr().unwrap()));
30+
//! assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.repr().unwrap()));
3131
//!
3232
//! // Python -> Rust
33-
//! let new_sample: Sample = depythonize(&obj.into_bound(py)).unwrap();
33+
//! let new_sample: Sample = depythonize(&obj).unwrap();
3434
//!
3535
//! assert_eq!(new_sample, sample);
3636
//! });
@@ -40,9 +40,9 @@ mod de;
4040
mod error;
4141
mod ser;
4242

43-
pub use crate::de::{depythonize, Depythonizer};
4443
#[allow(deprecated)]
45-
pub use crate::de::{depythonize_bound, depythonize_object};
44+
pub use crate::de::depythonize_bound;
45+
pub use crate::de::{depythonize, Depythonizer};
4646
pub use crate::error::{PythonizeError, Result};
4747
pub use crate::ser::{
4848
pythonize, pythonize_custom, PythonizeDefault, PythonizeDictType, PythonizeListType,

0 commit comments

Comments
 (0)