Skip to content

Commit 60c2c35

Browse files
committed
tweak tests and comment
1 parent b9d6c8a commit 60c2c35

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

‎src/validators/literal.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ impl<T: Debug> LiteralLookup<T> {
136136
}
137137
// must be an enum or bytes
138138
if let Some(expected_py) = &self.expected_py {
139-
// We don't use ? to unpack the result of get_item in the next line because unhashable
140-
// inputs will produce a TypeError, which in this case we just want to treat as a
141-
// validation failure
139+
// We don't use ? to unpack the result of `get_item` in the next line because unhashable
140+
// inputs will produce a TypeError, which in this case we just want to treat equivalently
141+
// to a failed lookup
142142
if let Ok(Some(v)) = expected_py.as_ref(py).get_item(input) {
143143
let id: usize = v.extract().unwrap();
144144
return Ok(Some((input, &self.values[id])));

‎tests/validators/test_union.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,5 +799,7 @@ class ModelA:
799799

800800
# validation against Literal[True] fails bc of the unhashable dict
801801
# A ValidationError is raised, not a ValueError, which allows the validation against the union to continue
802-
assert validator.validate_python({'a': 42})
803-
assert validator.validate_python(True)
802+
m = validator.validate_python({'a': 42})
803+
assert isinstance(m, ModelA)
804+
assert m.a == 42
805+
assert validator.validate_python(True) is True

0 commit comments

Comments
 (0)