Skip to content

Commit

Permalink
tweak tests and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 22, 2023
1 parent b9d6c8a commit 60c2c35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/validators/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ impl<T: Debug> LiteralLookup<T> {
}
// must be an enum or bytes
if let Some(expected_py) = &self.expected_py {
// We don't use ? to unpack the result of get_item in the next line because unhashable
// inputs will produce a TypeError, which in this case we just want to treat as a
// validation failure
// We don't use ? to unpack the result of `get_item` in the next line because unhashable
// inputs will produce a TypeError, which in this case we just want to treat equivalently
// to a failed lookup
if let Ok(Some(v)) = expected_py.as_ref(py).get_item(input) {
let id: usize = v.extract().unwrap();
return Ok(Some((input, &self.values[id])));
Expand Down
6 changes: 4 additions & 2 deletions tests/validators/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,5 +799,7 @@ class ModelA:

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

0 comments on commit 60c2c35

Please sign in to comment.