From 62556ffce00f8ad6c0702e60049d6209fe9d4703 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 13 Sep 2024 08:39:22 +0100 Subject: [PATCH] wip test PyO3 HEAD --- Cargo.toml | 4 ++-- crates/jiter/src/py_lossless_float.rs | 2 +- crates/jiter/src/py_string_cache.rs | 2 +- crates/jiter/src/python.rs | 6 +++--- crates/jiter/src/value.rs | 4 ++-- crates/jiter/tests/python.rs | 10 ++++------ 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d20b70e..a9fad8e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,5 +29,5 @@ inherits = "release" debug = true [workspace.dependencies] -pyo3 = { version = "0.22.0" } -pyo3-build-config = { version = "0.22.0" } +pyo3 = { git = "https://github.com/pyo3/pyo3" } +pyo3-build-config = { git = "https://github.com/pyo3/pyo3" } diff --git a/crates/jiter/src/py_lossless_float.rs b/crates/jiter/src/py_lossless_float.rs index 1d1f14b7..1f87ef21 100644 --- a/crates/jiter/src/py_lossless_float.rs +++ b/crates/jiter/src/py_lossless_float.rs @@ -91,6 +91,6 @@ static DECIMAL_TYPE: GILOnceCell> = GILOnceCell::new(); pub fn get_decimal_type(py: Python) -> PyResult<&Bound<'_, PyType>> { DECIMAL_TYPE - .get_or_try_init(py, || py.import_bound("decimal")?.getattr("Decimal")?.extract()) + .get_or_try_init(py, || py.import("decimal")?.getattr("Decimal")?.extract()) .map(|t| t.bind(py)) } diff --git a/crates/jiter/src/py_string_cache.rs b/crates/jiter/src/py_string_cache.rs index 21e69794..76b935ef 100644 --- a/crates/jiter/src/py_string_cache.rs +++ b/crates/jiter/src/py_string_cache.rs @@ -194,7 +194,7 @@ pub fn pystring_fast_new<'py>(py: Python<'py>, s: &str, ascii_only: bool) -> Bou if ascii_only { unsafe { pystring_ascii_new(py, s) } } else { - PyString::new_bound(py, s) + PyString::new(py, s) } } diff --git a/crates/jiter/src/python.rs b/crates/jiter/src/python.rs index b811d1c3..3aaa3082 100644 --- a/crates/jiter/src/python.rs +++ b/crates/jiter/src/python.rs @@ -145,7 +145,7 @@ impl<'j, StringCache: StringMaybeCache, KeyCheck: MaybeKeyCheck, ParseNumber: Ma let peek_first = match self.parser.array_first() { Ok(Some(peek)) => peek, Err(e) if !self._allow_partial_err(&e) => return Err(e), - Ok(None) | Err(_) => return Ok(PyList::empty_bound(py).into_any()), + Ok(None) | Err(_) => return Ok(PyList::empty(py).into_any()), }; let mut vec: SmallVec<[Bound<'_, PyAny>; 8]> = SmallVec::with_capacity(8); @@ -155,10 +155,10 @@ impl<'j, StringCache: StringMaybeCache, KeyCheck: MaybeKeyCheck, ParseNumber: Ma } } - Ok(PyList::new_bound(py, vec).into_any()) + Ok(PyList::new(py, vec).into_any()) } Peek::Object => { - let dict = PyDict::new_bound(py); + let dict = PyDict::new(py); if let Err(e) = self._parse_object(py, &dict) { if !self._allow_partial_err(&e) { return Err(e); diff --git a/crates/jiter/src/value.rs b/crates/jiter/src/value.rs index 4771a2ba..a4cf0492 100644 --- a/crates/jiter/src/value.rs +++ b/crates/jiter/src/value.rs @@ -40,9 +40,9 @@ impl pyo3::ToPyObject for JsonValue<'_> { Self::BigInt(b) => b.to_object(py), Self::Float(f) => f.to_object(py), Self::Str(s) => s.to_object(py), - Self::Array(v) => pyo3::types::PyList::new_bound(py, v.iter().map(|v| v.to_object(py))).to_object(py), + Self::Array(v) => pyo3::types::PyList::new(py, v.iter().map(|v| v.to_object(py))).to_object(py), Self::Object(o) => { - let dict = pyo3::types::PyDict::new_bound(py); + let dict = pyo3::types::PyDict::new(py); for (k, v) in o.iter() { dict.set_item(k, v.to_object(py)).unwrap(); } diff --git a/crates/jiter/tests/python.rs b/crates/jiter/tests/python.rs index 2124b9d6..e0460342 100644 --- a/crates/jiter/tests/python.rs +++ b/crates/jiter/tests/python.rs @@ -43,18 +43,16 @@ fn test_cache_into() { let c: StringCacheMode = false.to_object(py).extract(py).unwrap(); assert!(matches!(c, StringCacheMode::None)); - let c: StringCacheMode = PyString::new_bound(py, "all").extract().unwrap(); + let c: StringCacheMode = PyString::new(py, "all").extract().unwrap(); assert!(matches!(c, StringCacheMode::All)); - let c: StringCacheMode = PyString::new_bound(py, "keys").extract().unwrap(); + let c: StringCacheMode = PyString::new(py, "keys").extract().unwrap(); assert!(matches!(c, StringCacheMode::Keys)); - let c: StringCacheMode = PyString::new_bound(py, "none").extract().unwrap(); + let c: StringCacheMode = PyString::new(py, "none").extract().unwrap(); assert!(matches!(c, StringCacheMode::None)); - let e = PyString::new_bound(py, "wrong") - .extract::() - .unwrap_err(); + let e = PyString::new(py, "wrong").extract::().unwrap_err(); assert_eq!( e.to_string(), "ValueError: Invalid string cache mode, should be `'all'`, '`keys`', `'none`' or a `bool`"