Skip to content

Commit bd91c18

Browse files
authored
fix wasteful to_python() calls checking for undefined (#1580)
1 parent 730adc3 commit bd91c18

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/validators/model.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl ModelValidator {
263263
let output = self.validator.validate(py, input, state)?;
264264

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

306306
if self.root_model {
307-
let fields_set = if input.to_object(py).is(&self.undefined) {
307+
let fields_set = if input.as_python().is_some_and(|py_input| py_input.is(&self.undefined)) {
308308
PySet::empty(py)?
309309
} else {
310310
PySet::new(py, [&String::from(ROOT_FIELD)])?

src/validators/with_default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Validator for WithDefaultValidator {
157157
input: &(impl Input<'py> + ?Sized),
158158
state: &mut ValidationState<'_, 'py>,
159159
) -> ValResult<PyObject> {
160-
if input.to_object(py).is(&self.undefined) {
160+
if input.as_python().is_some_and(|py_input| py_input.is(&self.undefined)) {
161161
Ok(self.default_value(py, None::<usize>, state)?.unwrap())
162162
} else {
163163
match self.validator.validate(py, input, state) {

0 commit comments

Comments
 (0)