@@ -20,12 +20,12 @@ fn destructure_function_schema(schema: &PyDict) -> PyResult<(bool, &PyAny)> {
20
20
let func: & PyDict = schema. get_as_req ( intern ! ( schema. py( ) , "function" ) ) ?;
21
21
let call: & PyAny = func. get_as_req ( intern ! ( schema. py( ) , "call" ) ) ?;
22
22
let func_type: & str = func. get_as_req ( intern ! ( schema. py( ) , "type" ) ) ?;
23
- let is_model_instance_method = match func_type {
23
+ let is_field_validator = match func_type {
24
24
"field" => true ,
25
25
"general" => false ,
26
26
_ => unreachable ! ( ) ,
27
27
} ;
28
- Ok ( ( is_model_instance_method , call) )
28
+ Ok ( ( is_field_validator , call) )
29
29
}
30
30
31
31
impl BuildValidator for FunctionBuilder {
@@ -57,7 +57,7 @@ macro_rules! impl_build {
57
57
) -> PyResult <CombinedValidator > {
58
58
let py = schema. py( ) ;
59
59
let validator = build_validator( schema. get_as_req( intern!( py, "schema" ) ) ?, config, build_context) ?;
60
- let ( is_model_instance_method , function) = destructure_function_schema( schema) ?;
60
+ let ( is_field_validator , function) = destructure_function_schema( schema) ?;
61
61
let name = format!(
62
62
"{}[{}(), {}]" ,
63
63
$name,
@@ -72,7 +72,7 @@ macro_rules! impl_build {
72
72
None => py. None ( ) ,
73
73
} ,
74
74
name,
75
- is_model_instance_method ,
75
+ is_field_validator ,
76
76
}
77
77
. into( ) )
78
78
}
@@ -86,7 +86,7 @@ pub struct FunctionBeforeValidator {
86
86
func : PyObject ,
87
87
config : PyObject ,
88
88
name : String ,
89
- is_model_instance_method : bool ,
89
+ is_field_validator : bool ,
90
90
}
91
91
92
92
impl_build ! ( FunctionBeforeValidator , "function-before" ) ;
@@ -100,7 +100,7 @@ impl Validator for FunctionBeforeValidator {
100
100
slots : & ' data [ CombinedValidator ] ,
101
101
recursion_guard : & ' s mut RecursionGuard ,
102
102
) -> ValResult < ' data , PyObject > {
103
- let info = ValidationInfo :: new ( py, extra, & self . config , self . is_model_instance_method ) ?;
103
+ let info = ValidationInfo :: new ( py, extra, & self . config , self . is_field_validator ) ?;
104
104
let value = self
105
105
. func
106
106
. call1 ( py, ( input. to_object ( py) , info) )
@@ -129,7 +129,7 @@ pub struct FunctionAfterValidator {
129
129
func : PyObject ,
130
130
config : PyObject ,
131
131
name : String ,
132
- is_model_instance_method : bool ,
132
+ is_field_validator : bool ,
133
133
}
134
134
135
135
impl_build ! ( FunctionAfterValidator , "function-after" ) ;
@@ -144,7 +144,7 @@ impl Validator for FunctionAfterValidator {
144
144
recursion_guard : & ' s mut RecursionGuard ,
145
145
) -> ValResult < ' data , PyObject > {
146
146
let v = self . validator . validate ( py, input, extra, slots, recursion_guard) ?;
147
- let info = ValidationInfo :: new ( py, extra, & self . config , self . is_model_instance_method ) ?;
147
+ let info = ValidationInfo :: new ( py, extra, & self . config , self . is_field_validator ) ?;
148
148
self . func . call1 ( py, ( v, info) ) . map_err ( |e| convert_err ( py, e, input) )
149
149
}
150
150
@@ -166,21 +166,21 @@ pub struct FunctionPlainValidator {
166
166
func : PyObject ,
167
167
config : PyObject ,
168
168
name : String ,
169
- is_model_instance_method : bool ,
169
+ is_field_validator : bool ,
170
170
}
171
171
172
172
impl FunctionPlainValidator {
173
173
pub fn build ( schema : & PyDict , config : Option < & PyDict > ) -> PyResult < CombinedValidator > {
174
174
let py = schema. py ( ) ;
175
- let ( is_model_instance_method , function) = destructure_function_schema ( schema) ?;
175
+ let ( is_field_validator , function) = destructure_function_schema ( schema) ?;
176
176
Ok ( Self {
177
177
func : function. into_py ( py) ,
178
178
config : match config {
179
179
Some ( c) => c. into ( ) ,
180
180
None => py. None ( ) ,
181
181
} ,
182
182
name : format ! ( "function-plain[{}()]" , function_name( function) ?) ,
183
- is_model_instance_method ,
183
+ is_field_validator ,
184
184
}
185
185
. into ( ) )
186
186
}
@@ -195,7 +195,7 @@ impl Validator for FunctionPlainValidator {
195
195
_slots : & ' data [ CombinedValidator ] ,
196
196
_recursion_guard : & ' s mut RecursionGuard ,
197
197
) -> ValResult < ' data , PyObject > {
198
- let info = ValidationInfo :: new ( py, extra, & self . config , self . is_model_instance_method ) ?;
198
+ let info = ValidationInfo :: new ( py, extra, & self . config , self . is_field_validator ) ?;
199
199
self . func
200
200
. call1 ( py, ( input. to_object ( py) , info) )
201
201
. map_err ( |e| convert_err ( py, e, input) )
@@ -212,7 +212,7 @@ pub struct FunctionWrapValidator {
212
212
func : PyObject ,
213
213
config : PyObject ,
214
214
name : String ,
215
- is_model_instance_method : bool ,
215
+ is_field_validator : bool ,
216
216
}
217
217
218
218
impl_build ! ( FunctionWrapValidator , "function-wrap" ) ;
@@ -229,7 +229,7 @@ impl Validator for FunctionWrapValidator {
229
229
let call_next_validator = ValidatorCallable {
230
230
validator : InternalValidator :: new ( py, "ValidatorCallable" , & self . validator , slots, extra, recursion_guard) ,
231
231
} ;
232
- let info = ValidationInfo :: new ( py, extra, & self . config , self . is_model_instance_method ) ?;
232
+ let info = ValidationInfo :: new ( py, extra, & self . config , self . is_field_validator ) ?;
233
233
self . func
234
234
. call1 ( py, ( input. to_object ( py) , call_next_validator, info) )
235
235
. map_err ( |e| convert_err ( py, e, input) )
@@ -327,11 +327,11 @@ pub struct ValidationInfo {
327
327
}
328
328
329
329
impl ValidationInfo {
330
- fn new ( py : Python , extra : & Extra , config : & PyObject , is_model_instance_method : bool ) -> PyResult < Self > {
331
- let res = if is_model_instance_method {
330
+ fn new ( py : Python , extra : & Extra , config : & PyObject , is_field_validator : bool ) -> PyResult < Self > {
331
+ let res = if is_field_validator {
332
332
let field_name = match extra. field_name {
333
- Some ( v ) => v ,
334
- None => return Err ( PyRuntimeError :: new_err ( "This validator expected to be run inside the context of a model field but not model field was found" ) ) ,
333
+ Some ( field_name ) => field_name ,
334
+ _ => return Err ( PyRuntimeError :: new_err ( "This validator expected to be run inside the context of a model field but not model field was found" ) ) ,
335
335
} ;
336
336
Self {
337
337
config : config. clone_ref ( py) ,
0 commit comments