Skip to content

Commit 132f757

Browse files
committed
tweaks
1 parent ee72ba9 commit 132f757

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/validators/typed_dict.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl Validator for TypedDictValidator {
177177
Ok(v) => v,
178178
Err(ValError::LineErrors(line_errors)) => {
179179
let field_loc: LocItem = field.name.clone().into();
180-
if partial_last_key.as_ref().map_or(false, |l| l == &field_loc) {
180+
if partial_last_key.as_ref() == Some(&field_loc) {
181181
for err in line_errors {
182182
errors.push(err.with_outer_location(field_loc.clone()));
183183
}
@@ -307,12 +307,10 @@ impl Validator for TypedDictValidator {
307307
ExtraBehavior::Allow => {
308308
let py_key = either_str.as_py_string(self.py, self.state.cache_str());
309309
if let Some(validator) = self.extras_validator {
310-
let last_partial = if let Some(ref last_key) = self.partial_last_key {
310+
let last_partial = self.partial_last_key.as_ref().map_or(false, |last_key| {
311311
let key_loc: LocItem = raw_key.clone().into();
312312
&key_loc == last_key
313-
} else {
314-
false
315-
};
313+
});
316314
self.state.allow_partial = last_partial && validator.supports_partial();
317315
match validator.validate(self.py, value, self.state) {
318316
Ok(value) => {

tests/validators/test_allow_partial.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def test_partial_typed_dict():
172172
}
173173
]
174174
)
175+
with pytest.raises(ValidationError, match=r'c\s+Input should be greater than 10'):
176+
v.validate_python(MyMapping({'a': 11, 'c': 1, 'b': 12}), allow_partial=True)
175177

176178
# validate strings
177179
assert v.validate_strings({'a': '11', 'b': '22'}) == snapshot({'a': 11, 'b': 22})

0 commit comments

Comments
 (0)