diff --git a/src/serializers/fields.rs b/src/serializers/fields.rs index c7fe4c253..662ec936f 100644 --- a/src/serializers/fields.rs +++ b/src/serializers/fields.rs @@ -458,7 +458,7 @@ impl TypeSerializer for GeneralFieldsSerializer { map.end() } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "general-fields" } } diff --git a/src/serializers/type_serializers/complex.rs b/src/serializers/type_serializers/complex.rs index 1ec047395..d55c4b295 100644 --- a/src/serializers/type_serializers/complex.rs +++ b/src/serializers/type_serializers/complex.rs @@ -68,7 +68,7 @@ impl TypeSerializer for ComplexSerializer { } } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "complex" } } diff --git a/src/serializers/type_serializers/function.rs b/src/serializers/type_serializers/function.rs index 1214a666d..5916e60d7 100644 --- a/src/serializers/type_serializers/function.rs +++ b/src/serializers/type_serializers/function.rs @@ -183,7 +183,7 @@ impl FunctionPlainSerializer { fn retry_with_lax_check(&self) -> bool { self.fallback_serializer .as_ref() - .map_or(false, |f| f.retry_with_lax_check()) + .is_some_and(|f| f.retry_with_lax_check()) || self.return_serializer.retry_with_lax_check() } } diff --git a/src/validators/bytes.rs b/src/validators/bytes.rs index b9cc2dc69..d7c71e021 100644 --- a/src/validators/bytes.rs +++ b/src/validators/bytes.rs @@ -107,7 +107,7 @@ impl Validator for BytesConstrainedValidator { Ok(either_bytes.into_py_any(py)?) } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "constrained-bytes" } } diff --git a/src/validators/complex.rs b/src/validators/complex.rs index ff756707a..161daf1b8 100644 --- a/src/validators/complex.rs +++ b/src/validators/complex.rs @@ -49,7 +49,7 @@ impl Validator for ComplexValidator { Ok(res.into_pyobject(py)?.into()) } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "complex" } } diff --git a/src/validators/float.rs b/src/validators/float.rs index f2e662b08..30d3f3aa9 100644 --- a/src/validators/float.rs +++ b/src/validators/float.rs @@ -168,7 +168,7 @@ impl Validator for ConstrainedFloatValidator { Ok(either_float.into_py_any(py)?) } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "constrained-float" } } diff --git a/src/validators/int.rs b/src/validators/int.rs index 806584c60..dd30ef5c3 100644 --- a/src/validators/int.rs +++ b/src/validators/int.rs @@ -140,7 +140,7 @@ impl Validator for ConstrainedIntValidator { Ok(either_int.into_py_any(py)?) } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "constrained-int" } } diff --git a/src/validators/string.rs b/src/validators/string.rs index 3dfd3c8d1..69d126c8f 100644 --- a/src/validators/string.rs +++ b/src/validators/string.rs @@ -147,7 +147,7 @@ impl Validator for StrConstrainedValidator { Ok(py_string.into_py_any(py)?) } - fn get_name(&self) -> &str { + fn get_name(&self) -> &'static str { "constrained-str" } } diff --git a/src/validators/typed_dict.rs b/src/validators/typed_dict.rs index 9c6523189..4dc72a9e1 100644 --- a/src/validators/typed_dict.rs +++ b/src/validators/typed_dict.rs @@ -312,10 +312,7 @@ impl Validator for TypedDictValidator { ExtraBehavior::Allow => { let py_key = either_str.as_py_string(self.py, self.state.cache_str()); if let Some(validator) = self.extras_validator { - let last_partial = self.partial_last_key.as_ref().map_or(false, |last_key| { - let key_loc: LocItem = raw_key.clone().into(); - &key_loc == last_key - }); + let last_partial = self.partial_last_key.as_ref() == Some(&raw_key.clone().into()); self.state.allow_partial = match last_partial { true => self.allow_partial, false => false.into(), diff --git a/tests/benchmarks/nested_schema.py b/tests/benchmarks/nested_schema.py index 0d91d1217..423e7f1b8 100644 --- a/tests/benchmarks/nested_schema.py +++ b/tests/benchmarks/nested_schema.py @@ -40,7 +40,7 @@ def schema_using_defs() -> cs.CoreSchema: 'fields': { str(c): { 'type': 'model-field', - 'schema': {'type': 'definition-ref', 'schema_ref': f'model_{level+1}'}, + 'schema': {'type': 'definition-ref', 'schema_ref': f'model_{level + 1}'}, } for c in range(N) }, diff --git a/tests/test_json.py b/tests/test_json.py index c78ed3ad0..378214680 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -416,7 +416,7 @@ def test_json_bytes_base64_invalid(): { 'type': 'bytes_invalid_encoding', 'loc': (), - 'msg': f'Data should be valid base64: Invalid symbol {ord("!")}, offset {len(wrong_input)-1}.', + 'msg': f'Data should be valid base64: Invalid symbol {ord("!")}, offset {len(wrong_input) - 1}.', 'input': wrong_input, } ] diff --git a/tests/validators/test_int.py b/tests/validators/test_int.py index 47944126a..a07be2994 100644 --- a/tests/validators/test_int.py +++ b/tests/validators/test_int.py @@ -311,10 +311,7 @@ def test_int_strict(py_and_json: PyAndJson, input_value, expected): ( {'ge': 0}, -1, - Err( - 'Input should be greater than or equal to 0 ' - '[type=greater_than_equal, input_value=-1, input_type=int]' - ), + Err('Input should be greater than or equal to 0 [type=greater_than_equal, input_value=-1, input_type=int]'), ), ({'gt': 0}, 1, 1), ({'gt': 0}, 0, Err('Input should be greater than 0 [type=greater_than, input_value=0, input_type=int]')), diff --git a/tests/validators/test_json.py b/tests/validators/test_json.py index 9bd553d46..5d60d58f3 100644 --- a/tests/validators/test_json.py +++ b/tests/validators/test_json.py @@ -63,8 +63,7 @@ def test_any(py_and_json: PyAndJson, input_value, expected): pytest.param( 'xx', Err( - 'Invalid JSON: expected value at line 1 column 1 ' - "[type=json_invalid, input_value='xx', input_type=str]" + "Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='xx', input_type=str]" ), id='str_invalid', ), diff --git a/tests/validators/test_string.py b/tests/validators/test_string.py index ae5ced611..d7ae3e5ab 100644 --- a/tests/validators/test_string.py +++ b/tests/validators/test_string.py @@ -183,11 +183,7 @@ def test_invalid_regex(engine): if engine is None or engine == 'rust-regex': assert exc_info.value.args[0] == ( - 'Error building "str" validator:\n' - ' SchemaError: regex parse error:\n' - ' (abc\n' - ' ^\n' - 'error: unclosed group' + 'Error building "str" validator:\n SchemaError: regex parse error:\n (abc\n ^\nerror: unclosed group' ) elif engine == 'python-re': prefix = 'PatternError' if sys.version_info >= (3, 13) else 'error'