From 3c250348ba860199c05aaaa40d2944e45fb113b2 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Sun, 22 Dec 2024 14:09:46 +0100 Subject: [PATCH] chore(python): Fix deprecations Signed-off-by: Dmitry Dygalo --- crates/jsonschema-py/CHANGELOG.md | 1 + crates/jsonschema-py/src/lib.rs | 53 ++++++++++++++----------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/crates/jsonschema-py/CHANGELOG.md b/crates/jsonschema-py/CHANGELOG.md index f466e73a..8840b569 100644 --- a/crates/jsonschema-py/CHANGELOG.md +++ b/crates/jsonschema-py/CHANGELOG.md @@ -5,6 +5,7 @@ ### Changed - Improved error message for unknown formats. +- Update `pyo3` to `0.23`. ## [0.26.1] - 2024-10-29 diff --git a/crates/jsonschema-py/src/lib.rs b/crates/jsonschema-py/src/lib.rs index 41b3dcfa..bdcfc27c 100644 --- a/crates/jsonschema-py/src/lib.rs +++ b/crates/jsonschema-py/src/lib.rs @@ -79,39 +79,33 @@ impl ValidationErrorIter { } fn into_py_err(py: Python<'_>, error: jsonschema::ValidationError<'_>) -> PyResult { - let pyerror_type = PyType::new_bound::(py); + let pyerror_type = PyType::new::(py); let message = error.to_string(); let verbose_message = to_error_message(&error, message.clone()); let into_path = |segment: &str| { if let Ok(idx) = segment.parse::() { - idx.into_py(py) + idx.into_pyobject(py).and_then(PyObject::try_from) } else { - segment.into_py(py) + segment.into_pyobject(py).and_then(PyObject::try_from) } }; - let schema_path = PyList::new_bound( - py, - error - .schema_path - .as_str() - .split('/') - .skip(1) - .map(into_path) - .collect::>(), - ) - .unbind(); - let instance_path = PyList::new_bound( - py, - error - .instance_path - .as_str() - .split('/') - .skip(1) - .map(into_path) - .collect::>(), - ) - .unbind(); - Ok(PyErr::from_type_bound( + let elements = error + .schema_path + .as_str() + .split('/') + .skip(1) + .map(into_path) + .collect::, _>>()?; + let schema_path = PyList::new(py, elements)?.unbind(); + let elements = error + .instance_path + .as_str() + .split('/') + .skip(1) + .map(into_path) + .collect::, _>>()?; + let instance_path = PyList::new(py, elements)?.unbind(); + Ok(PyErr::from_type( pyerror_type, (message, verbose_message, schema_path, instance_path), )) @@ -161,8 +155,8 @@ fn make_options( let callback: Py = callback.clone().unbind(); let call_py_callback = move |value: &str| { Python::with_gil(|py| { - let value = PyString::new_bound(py, value); - callback.call_bound(py, (value,), None)?.is_truthy(py) + let value = PyString::new(py, value); + callback.call(py, (value,), None)?.is_truthy(py) }) }; options.with_format( @@ -719,7 +713,7 @@ fn jsonschema_rs(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_class::()?; module.add_class::()?; module.add_class::()?; - module.add("ValidationError", py.get_type_bound::())?; + module.add("ValidationError", py.get_type::())?; module.add("Draft4", DRAFT4)?; module.add("Draft6", DRAFT6)?; module.add("Draft7", DRAFT7)?; @@ -727,6 +721,7 @@ fn jsonschema_rs(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> { module.add("Draft202012", DRAFT202012)?; // Add build metadata to ease triaging incoming issues + #[allow(deprecated)] module.add("__build__", pyo3_built::pyo3_built!(py, build))?; Ok(())