Skip to content

Commit

Permalink
fix wasteful to_python() calls checking for undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Dec 12, 2024
1 parent 80756c1 commit 7e0390f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/validators/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl ModelValidator {
let output = self.validator.validate(py, input, state)?;

if self.root_model {
let fields_set = if input.to_object(py).is(&self.undefined) {
let fields_set = if input.as_python().is_some_and(|py_input| py_input.is(&self.undefined)) {
PySet::empty(py)?
} else {
PySet::new(py, [&String::from(ROOT_FIELD)])?
Expand Down Expand Up @@ -304,7 +304,7 @@ impl ModelValidator {
let instance = create_class(self.class.bind(py))?;

if self.root_model {
let fields_set = if input.to_object(py).is(&self.undefined) {
let fields_set = if input.as_python().is_some_and(|py_input| py_input.is(&self.undefined)) {
PySet::empty(py)?
} else {
PySet::new(py, [&String::from(ROOT_FIELD)])?
Expand Down
2 changes: 1 addition & 1 deletion src/validators/with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Validator for WithDefaultValidator {
input: &(impl Input<'py> + ?Sized),
state: &mut ValidationState<'_, 'py>,
) -> ValResult<PyObject> {
if input.to_object(py).is(&self.undefined) {
if input.as_python().is_some_and(|py_input| py_input.is(&self.undefined)) {
Ok(self.default_value(py, None::<usize>, state)?.unwrap())
} else {
match self.validator.validate(py, input, state) {
Expand Down

0 comments on commit 7e0390f

Please sign in to comment.