Skip to content

Commit c34243a

Browse files
committed
minimize changes to validators
1 parent e442820 commit c34243a

39 files changed

+163
-89
lines changed

Cargo.lock

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[package]
2+
rust-version = "1.59"
23
name = "pydantic-core"
34
version = "0.12.0"
45
edition = "2021"

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
stable
1+
nightly

src/validators/any.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use super::{BuildContext, BuildValidator, CombinedValidator, Extra, Validator};
1212
pub struct AnyValidator;
1313

1414
impl BuildValidator for AnyValidator {
15+
const EXPECTED_TYPE: &'static str = "any";
16+
1517
fn build(
1618
_schema: &PyDict,
1719
_config: Option<&PyDict>,
@@ -35,6 +37,6 @@ impl Validator for AnyValidator {
3537
}
3638

3739
fn get_name(&self) -> &str {
38-
"any"
40+
Self::EXPECTED_TYPE
3941
}
4042
}

src/validators/arguments.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct ArgumentsValidator {
3030
}
3131

3232
impl BuildValidator for ArgumentsValidator {
33+
const EXPECTED_TYPE: &'static str = "arguments";
34+
3335
fn build(
3436
schema: &PyDict,
3537
config: Option<&PyDict>,
@@ -313,6 +315,6 @@ impl Validator for ArgumentsValidator {
313315
}
314316

315317
fn get_name(&self) -> &str {
316-
"arguments"
318+
Self::EXPECTED_TYPE
317319
}
318320
}

src/validators/bool.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub struct BoolValidator {
1414
}
1515

1616
impl BuildValidator for BoolValidator {
17+
const EXPECTED_TYPE: &'static str = "bool";
18+
1719
fn build(
1820
schema: &PyDict,
1921
config: Option<&PyDict>,
@@ -41,6 +43,6 @@ impl Validator for BoolValidator {
4143
}
4244

4345
fn get_name(&self) -> &str {
44-
"bool"
46+
Self::EXPECTED_TYPE
4547
}
4648
}

src/validators/bytes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub struct BytesValidator {
1515
}
1616

1717
impl BuildValidator for BytesValidator {
18+
const EXPECTED_TYPE: &'static str = "bytes";
19+
1820
fn build(
1921
schema: &PyDict,
2022
config: Option<&PyDict>,
@@ -48,7 +50,7 @@ impl Validator for BytesValidator {
4850
}
4951

5052
fn get_name(&self) -> &str {
51-
"bytes"
53+
Self::EXPECTED_TYPE
5254
}
5355
}
5456

src/validators/call.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct CallValidator {
1919
}
2020

2121
impl BuildValidator for CallValidator {
22+
const EXPECTED_TYPE: &'static str = "call";
23+
2224
fn build(
2325
schema: &PyDict,
2426
config: Option<&PyDict>,
@@ -36,7 +38,7 @@ impl BuildValidator for CallValidator {
3638
};
3739
let function: &PyAny = schema.get_as_req(intern!(py, "function"))?;
3840
let function_name: &str = function.getattr(intern!(py, "__name__"))?.extract()?;
39-
let name = format!("{}[{function_name}]", "call");
41+
let name = format!("{}[{function_name}]", Self::EXPECTED_TYPE);
4042

4143
Ok(Self {
4244
function: function.to_object(py),

src/validators/callable.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use super::{BuildContext, BuildValidator, CombinedValidator, Extra, Validator};
1111
pub struct CallableValidator;
1212

1313
impl BuildValidator for CallableValidator {
14+
const EXPECTED_TYPE: &'static str = "callable";
15+
1416
fn build(
1517
_schema: &PyDict,
1618
_config: Option<&PyDict>,
@@ -36,6 +38,6 @@ impl Validator for CallableValidator {
3638
}
3739

3840
fn get_name(&self) -> &str {
39-
"callable"
41+
Self::EXPECTED_TYPE
4042
}
4143
}

src/validators/chain.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct ChainValidator {
1717
}
1818

1919
impl BuildValidator for ChainValidator {
20+
const EXPECTED_TYPE: &'static str = "chain";
21+
2022
fn build(
2123
schema: &PyDict,
2224
config: Option<&PyDict>,
@@ -42,7 +44,7 @@ impl BuildValidator for ChainValidator {
4244

4345
Ok(Self {
4446
steps,
45-
name: format!("{}[{descr}]", "chain"),
47+
name: format!("{}[{descr}]", Self::EXPECTED_TYPE),
4648
}
4749
.into())
4850
}

src/validators/custom_error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub struct CustomErrorValidator {
5959
}
6060

6161
impl BuildValidator for CustomErrorValidator {
62+
const EXPECTED_TYPE: &'static str = "custom-error";
63+
6264
fn build(
6365
schema: &PyDict,
6466
config: Option<&PyDict>,
@@ -67,7 +69,7 @@ impl BuildValidator for CustomErrorValidator {
6769
let custom_error = CustomError::build(schema)?.unwrap();
6870
let schema: &PyAny = schema.get_as_req(intern!(schema.py(), "schema"))?;
6971
let validator = Box::new(build_validator(schema, config, build_context)?);
70-
let name = format!("{}[{}]", "custom_error", validator.get_name());
72+
let name = format!("{}[{}]", Self::EXPECTED_TYPE, validator.get_name());
7173
Ok(Self {
7274
validator,
7375
name,

src/validators/date.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct DateValidator {
1919
}
2020

2121
impl BuildValidator for DateValidator {
22+
const EXPECTED_TYPE: &'static str = "date";
23+
2224
fn build(
2325
schema: &PyDict,
2426
config: Option<&PyDict>,
@@ -97,7 +99,7 @@ impl Validator for DateValidator {
9799
}
98100

99101
fn get_name(&self) -> &str {
100-
"date"
102+
Self::EXPECTED_TYPE
101103
}
102104
}
103105

src/validators/datetime.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct DateTimeValidator {
2020
}
2121

2222
impl BuildValidator for DateTimeValidator {
23+
const EXPECTED_TYPE: &'static str = "datetime";
24+
2325
fn build(
2426
schema: &PyDict,
2527
config: Option<&PyDict>,
@@ -101,7 +103,7 @@ impl Validator for DateTimeValidator {
101103
}
102104

103105
fn get_name(&self) -> &str {
104-
"datetime"
106+
Self::EXPECTED_TYPE
105107
}
106108
}
107109

0 commit comments

Comments
 (0)