Skip to content

Commit ac7ee00

Browse files
committed
moving missing logic to 2nd
1 parent a0bfacc commit ac7ee00

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/validators/enum_.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ impl<T: EnumValidateValue> Validator for EnumValidator<T> {
116116
},
117117
input,
118118
));
119-
} else if let Some(v) = T::validate_value(py, input, &self.lookup, strict)? {
120-
state.floor_exactness(Exactness::Lax);
119+
}
120+
121+
state.floor_exactness(Exactness::Lax);
122+
123+
if let Some(v) = T::validate_value(py, input, &self.lookup, strict)? {
121124
return Ok(v);
125+
} else if let Ok(res) = class.as_unbound().call1(py, (input.as_python(),)) {
126+
// as a last result, just try to initialize the enum with the input
127+
return Ok(res);
122128
} else if let Some(ref missing) = self.missing {
123-
state.floor_exactness(Exactness::Lax);
124129
let enum_value = missing.bind(py).call1((input.to_object(py),)).map_err(|_| {
125130
ValError::new(
126131
ErrorType::Enum {
@@ -145,10 +150,6 @@ impl<T: EnumValidateValue> Validator for EnumValidator<T> {
145150
));
146151
return Err(type_error.into());
147152
}
148-
} else if let Ok(res) = class.as_unbound().call1(py, (input.as_python(),)) {
149-
// as a last result, just try to initialize the enum with the input
150-
state.floor_exactness(Exactness::Lax);
151-
return Ok(res);
152153
}
153154

154155
Err(ValError::new(

0 commit comments

Comments
 (0)