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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

- Bump MSRV to 1.83.
- Update `pyo3` to 0.28.

## 0.27.0 - 2025-11-07
- Update to PyO3 0.27

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pythonize"
version = "0.27.0"
authors = ["David Hewitt <1939362+davidhewitt@users.noreply.github.com>"]
edition = "2021"
rust-version = "1.74"
rust-version = "1.83"
license = "MIT"
description = "Serde Serializer & Deserializer from Rust <--> Python, backed by PyO3."
homepage = "https://github.com/davidhewitt/pythonize"
Expand All @@ -13,11 +13,11 @@ documentation = "https://docs.rs/crate/pythonize/"

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

[dev-dependencies]
serde = { version = "1.0", default-features = false, features = ["derive"] }
pyo3 = { version = "0.27", default-features = false, features = ["auto-initialize", "macros", "py-clone"] }
pyo3 = { version = "0.28", default-features = false, features = ["auto-initialize", "macros", "py-clone"] }
serde_json = "1.0"
serde_bytes = "0.11"
maplit = "1.0.2"
Expand Down
46 changes: 22 additions & 24 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ mod test {
use super::*;
use crate::error::ErrorImpl;
use maplit::hashmap;
use pyo3::ffi::c_str;
use pyo3::{IntoPyObject, Python};
use serde_json::{json, Value as JsonValue};

Expand All @@ -545,7 +544,7 @@ mod test {

let expected = Empty;
let expected_json = json!(null);
let code = c_str!("None");
let code = c"None";
test_de(code, &expected, &expected_json);
}

Expand All @@ -571,7 +570,7 @@ mod test {
"baz": 45.23,
"qux": true
});
let code = c_str!("{'foo': 'Foo', 'bar': 8, 'baz': 45.23, 'qux': True}");
let code = c"{'foo': 'Foo', 'bar': 8, 'baz': 45.23, 'qux': True}";
test_de(code, &expected, &expected_json);
}

Expand All @@ -583,7 +582,7 @@ mod test {
bar: usize,
}

let code = c_str!("{'foo': 'Foo'}");
let code = c"{'foo': 'Foo'}";

Python::attach(|py| {
let locals = PyDict::new(py);
Expand All @@ -602,7 +601,7 @@ mod test {

let expected = TupleStruct("cat".to_string(), -10.05);
let expected_json = json!(["cat", -10.05]);
let code = c_str!("('cat', -10.05)");
let code = c"('cat', -10.05)";
test_de(code, &expected, &expected_json);
}

Expand All @@ -611,7 +610,7 @@ mod test {
#[derive(Debug, Deserialize, PartialEq)]
struct TupleStruct(String, f64);

let code = c_str!("('cat', -10.05, 'foo')");
let code = c"('cat', -10.05, 'foo')";

Python::attach(|py| {
let locals = PyDict::new(py);
Expand All @@ -630,63 +629,63 @@ mod test {

let expected = TupleStruct("cat".to_string(), -10.05);
let expected_json = json!(["cat", -10.05]);
let code = c_str!("['cat', -10.05]");
let code = c"['cat', -10.05]";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_tuple() {
let expected = ("foo".to_string(), 5);
let expected_json = json!(["foo", 5]);
let code = c_str!("('foo', 5)");
let code = c"('foo', 5)";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_tuple_from_pylist() {
let expected = ("foo".to_string(), 5);
let expected_json = json!(["foo", 5]);
let code = c_str!("['foo', 5]");
let code = c"['foo', 5]";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_vec_from_pyset() {
let expected = vec!["foo".to_string()];
let expected_json = json!(["foo"]);
let code = c_str!("{'foo'}");
let code = c"{'foo'}";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_vec_from_pyfrozenset() {
let expected = vec!["foo".to_string()];
let expected_json = json!(["foo"]);
let code = c_str!("frozenset({'foo'})");
let code = c"frozenset({'foo'})";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_vec() {
let expected = vec![3, 2, 1];
let expected_json = json!([3, 2, 1]);
let code = c_str!("[3, 2, 1]");
let code = c"[3, 2, 1]";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_vec_from_tuple() {
let expected = vec![3, 2, 1];
let expected_json = json!([3, 2, 1]);
let code = c_str!("(3, 2, 1)");
let code = c"(3, 2, 1)";
test_de(code, &expected, &expected_json);
}

#[test]
fn test_hashmap() {
let expected = hashmap! {"foo".to_string() => 4};
let expected_json = json!({"foo": 4 });
let code = c_str!("{'foo': 4}");
let code = c"{'foo': 4}";
test_de(code, &expected, &expected_json);
}

Expand All @@ -699,7 +698,7 @@ mod test {

let expected = Foo::Variant;
let expected_json = json!("Variant");
let code = c_str!("'Variant'");
let code = c"'Variant'";
test_de(code, &expected, &expected_json);
}

Expand All @@ -712,7 +711,7 @@ mod test {

let expected = Foo::Tuple(12, "cat".to_string());
let expected_json = json!({"Tuple": [12, "cat"]});
let code = c_str!("{'Tuple': [12, 'cat']}");
let code = c"{'Tuple': [12, 'cat']}";
test_de(code, &expected, &expected_json);
}

Expand All @@ -725,7 +724,7 @@ mod test {

let expected = Foo::NewType("cat".to_string());
let expected_json = json!({"NewType": "cat" });
let code = c_str!("{'NewType': 'cat'}");
let code = c"{'NewType': 'cat'}";
test_de(code, &expected, &expected_json);
}

Expand All @@ -741,7 +740,7 @@ mod test {
bar: 25,
};
let expected_json = json!({"Struct": {"foo": "cat", "bar": 25 }});
let code = c_str!("{'Struct': {'foo': 'cat', 'bar': 25}}");
let code = c"{'Struct': {'foo': 'cat', 'bar': 25}}";
test_de(code, &expected, &expected_json);
}
#[test]
Expand All @@ -754,7 +753,7 @@ mod test {

let expected = Foo::Tuple(12.0, 'c');
let expected_json = json!([12.0, 'c']);
let code = c_str!("[12.0, 'c']");
let code = c"[12.0, 'c']";
test_de(code, &expected, &expected_json);
}

Expand All @@ -768,7 +767,7 @@ mod test {

let expected = Foo::NewType("cat".to_string());
let expected_json = json!("cat");
let code = c_str!("'cat'");
let code = c"'cat'";
test_de(code, &expected, &expected_json);
}

Expand All @@ -785,7 +784,7 @@ mod test {
bar: [2, 5, 3, 1],
};
let expected_json = json!({"foo": ["a", "b", "c"], "bar": [2, 5, 3, 1]});
let code = c_str!("{'foo': ['a', 'b', 'c'], 'bar': [2, 5, 3, 1]}");
let code = c"{'foo': ['a', 'b', 'c'], 'bar': [2, 5, 3, 1]}";
test_de(code, &expected, &expected_json);
}

Expand Down Expand Up @@ -818,8 +817,7 @@ mod test {
};
let expected_json =
json!({"name": "SomeFoo", "bar": { "value": 13, "variant": { "Tuple": [-1.5, 8]}}});
let code =
c_str!("{'name': 'SomeFoo', 'bar': {'value': 13, 'variant': {'Tuple': [-1.5, 8]}}}");
let code = c"{'name': 'SomeFoo', 'bar': {'value': 13, 'variant': {'Tuple': [-1.5, 8]}}}";
test_de(code, &expected, &expected_json);
}

Expand Down Expand Up @@ -868,7 +866,7 @@ mod test {
fn test_char() {
let expected = 'a';
let expected_json = json!("a");
let code = c_str!("'a'");
let code = c"'a'";
test_de(code, &expected, &expected_json);
}

Expand Down
3 changes: 1 addition & 2 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,6 @@ impl<'py, P: PythonizeTypes> ser::SerializeStructVariant for PythonStructVariant
mod test {
use super::pythonize;
use maplit::hashmap;
use pyo3::ffi::c_str;
use pyo3::prelude::*;
use pyo3::pybacked::PyBackedStr;
use pyo3::types::{PyBytes, PyDict};
Expand All @@ -639,7 +638,7 @@ mod test {
locals.set_item("obj", obj)?;

py.run(
c_str!("import json; result = json.dumps(obj, separators=(',', ':'))"),
c"import json; result = json.dumps(obj, separators=(',', ':'))",
None,
Some(&locals),
)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_with_serde_path_to_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn test_de_invalid() {
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 cast as 'str'"
"root_map.nested_1.nested_key: unexpected type: 'int' object is not an instance of 'str'"
);
})
}
Expand Down
Loading