-
-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
When the arbitrary_precision feature is enabled, pythonize serializes all numbers like {'$serde_json::private::Number': '2'} instead of 2.
To reproduce
Cargo.toml
[package]
name = "pythonize_bug"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.27", features = ["extension-module"] }
pythonize = "0.27"
serde_json = { version = "1.0", features = ["arbitrary_precision"] }pyproject.toml
[build-system]
requires = ["maturin>=1.4,<2.0"]
build-backend = "maturin"
[project]
name = "pythonize_bug"
version = "0.1.0"
[tool.maturin]
module-name = "pythonize_bug"src/lib.rs
use pyo3::prelude::*;
use pythonize::{depythonize, pythonize};
use serde_json::Value;
#[pyfunction]
fn test_roundtrip<'py>(py: Python<'py>, obj: Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> {
let value: Value = depythonize(&obj)?;
Ok(pythonize(py, &value)?)
}
#[pymodule]
fn pythonize_bug(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(test_roundtrip, m)?)?;
Ok(())
}Install
uv venv
uv pip install maturin
uv run maturin developRun
$ uv run python -c 'from pythonize_bug import test_roundtrip; print(test_roundtrip(18446744073709551615))'
{'$serde_json::private::Number': '18446744073709551615'}
If , features = ["arbitrary_precision"] is removed from Cargo.toml and uv run maturin develop is run:
$ uv run python -c 'from pythonize_bug import test_roundtrip; print(test_roundtrip(18446744073709551615))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
Exception: JSON number out of range
Metadata
Metadata
Assignees
Labels
No labels