chore: Avoid usage of deprecated PyO3 traits

This commit is contained in:
Dmitry Dygalo 2022-05-12 16:36:42 +02:00 committed by Dmitry Dygalo
parent a5cd893363
commit 5feb0d2308
3 changed files with 12 additions and 22 deletions

View File

@ -132,9 +132,9 @@ dependencies = [
[[package]]
name = "fancy-regex"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "367dc842ccf982f1cebf8be5ecb65b347db9fd18bdd7fd255c5ad0d3fc02f6a6"
checksum = "0678ab2d46fa5195aaf59ad034c083d351377d4af57f3e073c074d0da3e3c766"
dependencies = [
"bit-set",
"regex",

View File

@ -21,7 +21,7 @@ use pyo3::{
exceptions::{self, PyValueError},
prelude::*,
types::{PyAny, PyList, PyType},
wrap_pyfunction, AsPyPointer, PyIterProtocol, PyObjectProtocol,
wrap_pyfunction, AsPyPointer,
};
#[macro_use]
extern crate pyo3_built;
@ -64,14 +64,10 @@ impl ValidationError {
instance_path,
}
}
}
#[pyproto]
impl<'p> PyObjectProtocol<'p> for ValidationError {
fn __str__(&'p self) -> PyResult<String> {
fn __str__(&self) -> PyResult<String> {
Ok(self.verbose_message.clone())
}
fn __repr__(&'p self) -> PyResult<String> {
fn __repr__(&self) -> PyResult<String> {
Ok(format!("<ValidationError: '{}'>", self.message))
}
}
@ -80,13 +76,12 @@ impl<'p> PyObjectProtocol<'p> for ValidationError {
struct ValidationErrorIter {
iter: std::vec::IntoIter<PyErr>,
}
#[pyproto]
impl PyIterProtocol for ValidationErrorIter {
fn __iter__(slf: PyRef<Self>) -> PyRef<Self> {
#[pymethods]
impl ValidationErrorIter {
fn __iter__(slf: PyRef<'_, Self>) -> PyRef<'_, Self> {
slf
}
fn __next__(mut slf: PyRefMut<Self>) -> Option<PyErr> {
fn __next__(mut slf: PyRefMut<'_, Self>) -> Option<PyErr> {
slf.iter.next()
}
}
@ -328,6 +323,8 @@ struct JSONSchema {
repr: String,
}
const SCHEMA_LENGTH_LIMIT: usize = 32;
fn get_schema_repr(schema: &serde_json::Value) -> String {
// It could be more efficient, without converting the whole Value to a string
let mut repr = schema.to_string();
@ -441,12 +438,6 @@ impl JSONSchema {
fn iter_errors(&self, py: Python<'_>, instance: &PyAny) -> PyResult<ValidationErrorIter> {
iter_on_error(py, &self.schema, instance)
}
}
const SCHEMA_LENGTH_LIMIT: usize = 32;
#[pyproto]
impl<'p> PyObjectProtocol<'p> for JSONSchema {
fn __repr__(&self) -> PyResult<String> {
Ok(format!("<JSONSchema: {}>", self.repr))
}

View File

@ -3,8 +3,7 @@ use pyo3::ffi::{
PyMapping_GetItemString, PyObject, PyObject_GenericGetDict, PyTuple_New, PyTypeObject,
PyUnicode_New, Py_DECREF, Py_None, Py_TYPE, Py_True,
};
use std::os::raw::c_char;
use std::sync::Once;
use std::{os::raw::c_char, sync::Once};
pub static mut TRUE: *mut pyo3::ffi::PyObject = 0 as *mut pyo3::ffi::PyObject;