Skip to content

Commit 0e1dedd

Browse files
committed
remove extra traits
1 parent 40f3bbe commit 0e1dedd

File tree

2 files changed

+2
-32
lines changed

2 files changed

+2
-32
lines changed

src/build_tools.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::error::Error;
22
use std::fmt;
33

4-
use crate::tools::py_err;
5-
use pyo3::exceptions::{PyException, PyTypeError};
4+
use pyo3::exceptions::PyException;
65
use pyo3::prelude::*;
76
use pyo3::types::{PyDict, PyList, PyString};
87
use pyo3::{intern, FromPyObject, PyErrArguments};
@@ -196,30 +195,3 @@ impl ExtraBehavior {
196195
Ok(res)
197196
}
198197
}
199-
200-
impl ToPyObject for ExtraBehavior {
201-
fn to_object(&self, _py: Python) -> PyObject {
202-
match self {
203-
ExtraBehavior::Allow => ExtraBehavior::Allow.to_object(_py),
204-
ExtraBehavior::Ignore => ExtraBehavior::Ignore.to_object(_py),
205-
ExtraBehavior::Forbid => ExtraBehavior::Forbid.to_object(_py),
206-
}
207-
}
208-
}
209-
210-
impl FromPyObject<'_> for ExtraBehavior {
211-
fn extract(obj: &PyAny) -> PyResult<Self> {
212-
if let Ok(string) = obj.extract::<String>() {
213-
Ok(match string.as_str() {
214-
"allow" => ExtraBehavior::Allow,
215-
"ignore" => ExtraBehavior::Ignore,
216-
"forbid" => ExtraBehavior::Forbid,
217-
_ => {
218-
return py_err!(PyTypeError; "Invalid string for ExtraBehavior. Possible values are allow, ignore and forbid")
219-
}
220-
})
221-
} else {
222-
py_err!(PyTypeError; "Expected string value, got {}", obj.get_type())
223-
}
224-
}
225-
}

src/validators/arguments.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ impl BuildValidator for ArgumentsValidator {
120120
None => None,
121121
},
122122
loc_by_alias: config.get_as(intern!(py, "loc_by_alias"))?.unwrap_or(true),
123-
extra: config
124-
.get_as(intern!(py, "extra_fields_behavior"))?
125-
.unwrap_or(ExtraBehavior::Forbid),
123+
extra: ExtraBehavior::from_schema_or_config(py, schema, config, ExtraBehavior::Forbid)?,
126124
}
127125
.into())
128126
}

0 commit comments

Comments
 (0)