@@ -16,11 +16,16 @@ use super::{build_validator, BuildContext, BuildValidator, CombinedValidator, Ex
16
16
17
17
pub struct FunctionBuilder ;
18
18
19
- fn destructure_function_schema ( schema : & PyDict ) -> PyResult < ( & str , & PyAny ) > {
19
+ 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
- Ok ( ( func_type, call) )
23
+ let is_model_instance_method = match func_type {
24
+ "method" => true ,
25
+ "function" => false ,
26
+ _ => unreachable ! ( ) ,
27
+ } ;
28
+ Ok ( ( is_model_instance_method, call) )
24
29
}
25
30
26
31
impl BuildValidator for FunctionBuilder {
@@ -52,12 +57,7 @@ macro_rules! impl_build {
52
57
) -> PyResult <CombinedValidator > {
53
58
let py = schema. py( ) ;
54
59
let validator = build_validator( schema. get_as_req( intern!( py, "schema" ) ) ?, config, build_context) ?;
55
- let ( func_type, function) = destructure_function_schema( schema) ?;
56
- let is_model_instance_method = match func_type {
57
- "method" => true ,
58
- "function" => false ,
59
- _ => unreachable!( ) ,
60
- } ;
60
+ let ( is_model_instance_method, function) = destructure_function_schema( schema) ?;
61
61
let name = format!(
62
62
"{}[{}(), {}]" ,
63
63
$name,
@@ -172,12 +172,7 @@ pub struct FunctionPlainValidator {
172
172
impl FunctionPlainValidator {
173
173
pub fn build ( schema : & PyDict , config : Option < & PyDict > ) -> PyResult < CombinedValidator > {
174
174
let py = schema. py ( ) ;
175
- let ( func_type, function) = destructure_function_schema ( schema) ?;
176
- let is_model_instance_method = match func_type {
177
- "method" => true ,
178
- "function" => false ,
179
- _ => unreachable ! ( ) ,
180
- } ;
175
+ let ( is_model_instance_method, function) = destructure_function_schema ( schema) ?;
181
176
Ok ( Self {
182
177
func : function. into_py ( py) ,
183
178
config : match config {
0 commit comments