Skip to content

Commit 7fb03b2

Browse files
Copilotyouknowone
andcommitted
Adjust __hash__ wrapper conversion
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
1 parent 2767232 commit 7fb03b2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/vm/src/types/slot.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
66
builtins::{PyInt, PyStr, PyStrInterned, PyStrRef, PyType, PyTypeRef},
77
bytecode::ComparisonOperator,
8-
common::hash::{PyHash, hash_bigint},
8+
common::hash::{fix_sentinel, hash_bigint, PyHash},
99
convert::ToPyObject,
1010
function::{
1111
Either, FromArgs, FuncArgs, OptionalArg, PyComparisonValue, PyMethodDef, PySetterValue,
@@ -410,7 +410,12 @@ fn hash_wrapper(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyHash> {
410410
let py_int = hash_obj
411411
.downcast_ref::<PyInt>()
412412
.ok_or_else(|| vm.new_type_error("__hash__ method should return an integer"))?;
413-
Ok(hash_bigint(py_int.as_bigint()))
413+
let big_int = py_int.as_bigint();
414+
let hash = big_int
415+
.to_i64()
416+
.map(fix_sentinel)
417+
.unwrap_or_else(|| hash_bigint(big_int));
418+
Ok(hash)
414419
}
415420

416421
/// Marks a type as unhashable. Similar to PyObject_HashNotImplemented in CPython

0 commit comments

Comments
 (0)