diff --git a/src/common/missing_sentinel.rs b/src/common/missing_sentinel.rs index b23da9bd0..8ec469511 100644 --- a/src/common/missing_sentinel.rs +++ b/src/common/missing_sentinel.rs @@ -4,7 +4,7 @@ use pyo3::sync::GILOnceCell; static MISSING_SENTINEL_OBJECT: GILOnceCell> = GILOnceCell::new(); -pub fn get_missing_sentinel_object(py: Python) -> &Bound<'_, PyAny> { +pub fn get_missing_sentinel_object(py: Python<'_>) -> &Bound<'_, PyAny> { MISSING_SENTINEL_OBJECT .get_or_init(py, || { py.import(intern!(py, "pydantic_core")) diff --git a/src/errors/types.rs b/src/errors/types.rs index d2420629f..25f5eaaf2 100644 --- a/src/errors/types.rs +++ b/src/errors/types.rs @@ -18,7 +18,7 @@ use crate::tools::{extract_i64, py_err, py_error_type}; use super::PydanticCustomError; #[pyfunction] -pub fn list_all_errors(py: Python) -> PyResult> { +pub fn list_all_errors(py: Python<'_>) -> PyResult> { let mut errors: Vec> = Vec::with_capacity(100); for error_type in ErrorType::iter() { if !matches!(error_type, ErrorType::CustomError { .. }) { diff --git a/src/errors/validation_exception.rs b/src/errors/validation_exception.rs index d4e40ebd9..f4052c8db 100644 --- a/src/errors/validation_exception.rs +++ b/src/errors/validation_exception.rs @@ -238,7 +238,7 @@ fn get_formated_url(py: Python) -> &'static str { URL_PREFIX.get_or_init(py, || format!("https://errors.pydantic.dev/{pydantic_version}/v/")) } -fn get_url_prefix(py: Python, include_url: bool) -> Option<&str> { +fn get_url_prefix(py: Python<'_>, include_url: bool) -> Option<&str> { if include_url { Some(get_formated_url(py)) } else { diff --git a/src/input/input_python.rs b/src/input/input_python.rs index a51307b22..dcd028f2a 100644 --- a/src/input/input_python.rs +++ b/src/input/input_python.rs @@ -49,7 +49,7 @@ use super::{ static FRACTION_TYPE: GILOnceCell> = GILOnceCell::new(); -pub fn get_fraction_type(py: Python) -> &Bound<'_, PyType> { +pub fn get_fraction_type(py: Python<'_>) -> &Bound<'_, PyType> { FRACTION_TYPE .get_or_init(py, || { py.import("fractions") diff --git a/src/input/return_enums.rs b/src/input/return_enums.rs index bada53ace..41e815c21 100644 --- a/src/input/return_enums.rs +++ b/src/input/return_enums.rs @@ -474,7 +474,7 @@ pub enum EitherString<'a> { } impl<'a> EitherString<'a> { - pub fn as_cow(&self) -> ValResult> { + pub fn as_cow(&self) -> ValResult> { match self { Self::Cow(data) => Ok(data.clone()), Self::Py(py_str) => Ok(Cow::Borrowed(py_string_str(py_str)?)), diff --git a/src/input/shared.rs b/src/input/shared.rs index 8ca9c0013..a254c6a28 100644 --- a/src/input/shared.rs +++ b/src/input/shared.rs @@ -11,7 +11,7 @@ use crate::errors::{ErrorTypeDefaults, ValError, ValResult}; use super::{EitherFloat, EitherInt, Input}; static ENUM_META_OBJECT: GILOnceCell> = GILOnceCell::new(); -pub fn get_enum_meta_object(py: Python) -> &Bound<'_, PyAny> { +pub fn get_enum_meta_object(py: Python<'_>) -> &Bound<'_, PyAny> { ENUM_META_OBJECT .get_or_init(py, || { py.import(intern!(py, "enum")) @@ -108,7 +108,7 @@ pub fn str_as_float<'py>(input: &(impl Input<'py> + ?Sized), str: &str) -> ValRe } } -fn clean_int_str(mut s: &str) -> Option> { +fn clean_int_str(mut s: &str) -> Option> { let len_before = s.len(); // strip leading and trailing whitespace diff --git a/src/validators/complex.rs b/src/validators/complex.rs index 98ffc7dfe..5b32bb4fc 100644 --- a/src/validators/complex.rs +++ b/src/validators/complex.rs @@ -11,7 +11,7 @@ use super::{BuildValidator, CombinedValidator, DefinitionsBuilder, ValidationSta static COMPLEX_TYPE: GILOnceCell> = GILOnceCell::new(); -pub fn get_complex_type(py: Python) -> &Bound<'_, PyType> { +pub fn get_complex_type(py: Python<'_>) -> &Bound<'_, PyType> { COMPLEX_TYPE .get_or_init(py, || py.get_type::().into()) .bind(py) diff --git a/src/validators/dataclass.rs b/src/validators/dataclass.rs index 9cfb9dbae..9f316f881 100644 --- a/src/validators/dataclass.rs +++ b/src/validators/dataclass.rs @@ -542,8 +542,8 @@ impl Validator for DataclassValidator { // if the model has a generic origin, we allow input data to be instances of the generic origin rather than the class, // as cases like isinstance(SomeModel[Int], SomeModel[Any]) fail the isinstance check, but are valid, we just have to enforce // that the data is revalidated, hence we set force_revalidate to true - if generic_origin_class.is_some() { - match input_as_python_instance(input, generic_origin_class.unwrap()) { + if let Some(generic_origin) = generic_origin_class { + match input_as_python_instance(input, generic_origin) { Some(x) => (Some(x), true), None => (None, false), } diff --git a/src/validators/decimal.rs b/src/validators/decimal.rs index a2a9e0b5b..2f2fd6231 100644 --- a/src/validators/decimal.rs +++ b/src/validators/decimal.rs @@ -16,7 +16,7 @@ use super::{BuildValidator, CombinedValidator, DefinitionsBuilder, ValidationSta static DECIMAL_TYPE: GILOnceCell> = GILOnceCell::new(); -pub fn get_decimal_type(py: Python) -> &Bound<'_, PyType> { +pub fn get_decimal_type(py: Python<'_>) -> &Bound<'_, PyType> { DECIMAL_TYPE .get_or_init(py, || { py.import("decimal") diff --git a/src/validators/model.rs b/src/validators/model.rs index f2c3658e8..5797a59b5 100644 --- a/src/validators/model.rs +++ b/src/validators/model.rs @@ -140,8 +140,8 @@ impl Validator for ModelValidator { // if the model has a generic origin, we allow input data to be instances of the generic origin rather than the class, // as cases like isinstance(SomeModel[Int], SomeModel[Any]) fail the isinstance check, but are valid, we just have to enforce // that the data is revalidated, hence we set force_revalidate to true - if generic_origin_class.is_some() { - match input_as_python_instance(input, generic_origin_class.unwrap()) { + if let Some(generic_origin) = generic_origin_class { + match input_as_python_instance(input, generic_origin) { Some(x) => (Some(x), true), None => (None, false), } diff --git a/src/validators/uuid.rs b/src/validators/uuid.rs index 9ad4eb3b9..9e2694529 100644 --- a/src/validators/uuid.rs +++ b/src/validators/uuid.rs @@ -30,7 +30,7 @@ fn import_type(py: Python, module: &str, attr: &str) -> PyResult> { py.import(module)?.getattr(attr)?.extract() } -fn get_uuid_type(py: Python) -> PyResult<&Bound<'_, PyType>> { +fn get_uuid_type(py: Python<'_>) -> PyResult<&Bound<'_, PyType>> { Ok(UUID_TYPE .get_or_init(py, || import_type(py, "uuid", "UUID").unwrap()) .bind(py))