From 9247c69579fc270deeadb6dfeff6d23348e23f8a Mon Sep 17 00:00:00 2001 From: Preetham Pemmasani <75422607+ppmpreetham@users.noreply.github.com> Date: Wed, 19 Nov 2025 00:10:56 +0530 Subject: [PATCH 1/2] convert to sonic_rs --- Cargo.toml | 2 +- src/de.rs | 44 +++++++++++++++++++------------------- src/ser.rs | 2 +- tests/test_custom_types.rs | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a714a3..2d1bf46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,11 +14,11 @@ documentation = "https://docs.rs/crate/pythonize/" [dependencies] serde = { version = "1.0", default-features = false, features = ["std"] } pyo3 = { version = "0.27", default-features = false } +sonic-rs = "0.5.6" [dev-dependencies] serde = { version = "1.0", default-features = false, features = ["derive"] } 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" serde_path_to_error = "0.1.15" diff --git a/src/de.rs b/src/de.rs index a30dbca..03dc3d3 100644 --- a/src/de.rs +++ b/src/de.rs @@ -522,7 +522,7 @@ mod test { use maplit::hashmap; use pyo3::ffi::c_str; use pyo3::{IntoPyObject, Python}; - use serde_json::{json, Value as JsonValue}; + use sonic_rs::{json, Value as JsonValue}; fn test_de(code: &CStr, expected: &T, expected_json: &JsonValue) where @@ -826,26 +826,26 @@ mod test { #[test] fn test_int_limits() { Python::attach(|py| { - // serde_json::Value supports u64 and i64 as maximum sizes - let _: serde_json::Value = depythonize(&u8::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&u8::MIN.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i8::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i8::MIN.into_pyobject(py).unwrap()).unwrap(); - - let _: serde_json::Value = depythonize(&u16::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&u16::MIN.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i16::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i16::MIN.into_pyobject(py).unwrap()).unwrap(); - - let _: serde_json::Value = depythonize(&u32::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&u32::MIN.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i32::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i32::MIN.into_pyobject(py).unwrap()).unwrap(); - - let _: serde_json::Value = depythonize(&u64::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&u64::MIN.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i64::MAX.into_pyobject(py).unwrap()).unwrap(); - let _: serde_json::Value = depythonize(&i64::MIN.into_pyobject(py).unwrap()).unwrap(); + // sonic_rs::Value supports u64 and i64 as maximum sizes + let _: sonic_rs::Value = depythonize(&u8::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&u8::MIN.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i8::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i8::MIN.into_pyobject(py).unwrap()).unwrap(); + + let _: sonic_rs::Value = depythonize(&u16::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&u16::MIN.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i16::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i16::MIN.into_pyobject(py).unwrap()).unwrap(); + + let _: sonic_rs::Value = depythonize(&u32::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&u32::MIN.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i32::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i32::MIN.into_pyobject(py).unwrap()).unwrap(); + + let _: sonic_rs::Value = depythonize(&u64::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&u64::MIN.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i64::MAX.into_pyobject(py).unwrap()).unwrap(); + let _: sonic_rs::Value = depythonize(&i64::MIN.into_pyobject(py).unwrap()).unwrap(); let _: u128 = depythonize(&u128::MAX.into_pyobject(py).unwrap()).unwrap(); let _: i128 = depythonize(&u128::MIN.into_pyobject(py).unwrap()).unwrap(); @@ -882,7 +882,7 @@ mod test { .unwrap() .call0() .unwrap(); - let err = depythonize::(&obj).unwrap_err(); + let err = depythonize::(&obj).unwrap_err(); assert!(matches!( *err.inner, ErrorImpl::UnsupportedType(name) if name == "Decimal" diff --git a/src/ser.rs b/src/ser.rs index c8e6dd1..16410c0 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -647,7 +647,7 @@ mod test { let result = result.extract::()?; assert_eq!(result, expected); - assert_eq!(serde_json::to_string(&src).unwrap(), expected); + assert_eq!(sonic_rs::to_string(&src).unwrap(), expected); Ok(()) }) diff --git a/tests/test_custom_types.rs b/tests/test_custom_types.rs index 27888d0..8b9ce64 100644 --- a/tests/test_custom_types.rs +++ b/tests/test_custom_types.rs @@ -11,7 +11,7 @@ use pythonize::{ PythonizeNamedMappingType, PythonizeTypes, PythonizeUnnamedMappingAdapter, Pythonizer, }; use serde::Serialize; -use serde_json::{json, Value}; +use sonic_rs::{json, Value}; #[pyclass(sequence)] struct CustomList { From cba45a1fe63d4656c476b055e384954987833f1a Mon Sep 17 00:00:00 2001 From: Preetham Pemmasani <75422607+ppmpreetham@users.noreply.github.com> Date: Wed, 19 Nov 2025 00:11:04 +0530 Subject: [PATCH 2/2] change: readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2667523..a51f35e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is an experimental serializer for Rust's serde ecosystem, which can convert Rust objects to Python values and back. -At the moment the Python structures it produces should be _very_ similar to those which are produced by `serde_json`; i.e. calling Python's `json.loads()` on a value encoded by `serde_json` should produce an identical structure to +At the moment the Python structures it produces should be _very_ similar to those which are produced by `sonic_rs`; i.e. calling Python's `json.loads()` on a value encoded by `sonic_rs` should produce an identical structure to that which is produced directly by `pythonize`. ## Usage