Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using ? with get_item to handle unhashable inputs properly #1089

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
avoid using ? with get item to handle unhashable inputs properly
  • Loading branch information
sydney-runkle committed Nov 21, 2023
commit 03d3300de87a213f22788e7cadd8466d87c8cf2c
5 changes: 4 additions & 1 deletion src/validators/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ impl<T: Debug> LiteralLookup<T> {
}
// must be an enum or bytes
if let Some(expected_py) = &self.expected_py {
if let Some(v) = expected_py.as_ref(py).get_item(input)? {
// 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
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