@@ -35,7 +35,7 @@ pub struct LiteralLookup<T: Debug> {
35
35
expected_py_dict : Option < Py < PyDict > > ,
36
36
// Catch all for unhashable types like list
37
37
expected_py_values : Option < Vec < ( Py < PyAny > , usize ) > > ,
38
- // Fallback for ints, bools, and strings to use Python equality checks
38
+ // Fallback for ints, bools, and strings to use Python hash and equality checks
39
39
expected_py_primitives : Option < Vec < ( Py < PyAny > , usize ) > > ,
40
40
41
41
pub values : Vec < T > ,
@@ -159,9 +159,17 @@ impl<T: Debug> LiteralLookup<T> {
159
159
160
160
if let Some ( expected_py_primitives) = & self . expected_py_primitives {
161
161
let py_input = py_input. get_or_insert_with ( || input. to_object ( py) ) ;
162
+ let py_input_bound = py_input. bind ( py) ;
163
+
162
164
for ( k, id) in expected_py_primitives {
163
- if k. bind ( py) . eq ( & * py_input) . unwrap_or ( false ) {
164
- return Ok ( Some ( ( input, & self . values [ * id] ) ) ) ;
165
+ let bound_k = k. bind ( py) ;
166
+ if bound_k. eq ( & * py_input) . unwrap_or ( false ) {
167
+ match ( bound_k. hash ( ) , py_input_bound. hash ( ) ) {
168
+ ( Ok ( k_hash) , Ok ( input_hash) ) if k_hash == input_hash => {
169
+ return Ok ( Some ( ( input, & self . values [ * id] ) ) ) ;
170
+ }
171
+ _ => continue , // Skip to the next item on hash failure or mismatch
172
+ }
165
173
}
166
174
}
167
175
} ;
0 commit comments