Skip to content

Commit 04bc191

Browse files
committed
move logic into destructure_function_schema
1 parent a95e836 commit 04bc191

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

rust-toolchain

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

src/validators/function.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ use super::{build_validator, BuildContext, BuildValidator, CombinedValidator, Ex
1616

1717
pub struct FunctionBuilder;
1818

19-
fn destructure_function_schema(schema: &PyDict) -> PyResult<(&str, &PyAny)> {
19+
fn destructure_function_schema(schema: &PyDict) -> PyResult<(bool, &PyAny)> {
2020
let func: &PyDict = schema.get_as_req(intern!(schema.py(), "function"))?;
2121
let call: &PyAny = func.get_as_req(intern!(schema.py(), "call"))?;
2222
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))
2429
}
2530

2631
impl BuildValidator for FunctionBuilder {
@@ -52,12 +57,7 @@ macro_rules! impl_build {
5257
) -> PyResult<CombinedValidator> {
5358
let py = schema.py();
5459
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)?;
6161
let name = format!(
6262
"{}[{}(), {}]",
6363
$name,
@@ -172,12 +172,7 @@ pub struct FunctionPlainValidator {
172172
impl FunctionPlainValidator {
173173
pub fn build(schema: &PyDict, config: Option<&PyDict>) -> PyResult<CombinedValidator> {
174174
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)?;
181176
Ok(Self {
182177
func: function.into_py(py),
183178
config: match config {

0 commit comments

Comments
 (0)