Skip to content

Commit

Permalink
wip test PyO3 HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Sep 27, 2024
1 parent 4af2c1c commit 62556ff
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion crates/jiter/src/py_lossless_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ static DECIMAL_TYPE: GILOnceCell<Py<PyType>> = 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))
}
2 changes: 1 addition & 1 deletion crates/jiter/src/py_string_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/jiter/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crates/jiter/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
10 changes: 4 additions & 6 deletions crates/jiter/tests/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<StringCacheMode>()
.unwrap_err();
let e = PyString::new(py, "wrong").extract::<StringCacheMode>().unwrap_err();
assert_eq!(
e.to_string(),
"ValueError: Invalid string cache mode, should be `'all'`, '`keys`', `'none`' or a `bool`"
Expand Down

0 comments on commit 62556ff

Please sign in to comment.