Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Fix TypeError when hashing tuples/frozensets containing large ints
hash(n) for 2**53 < n < 2**61 is a JS BigInt (the exact value, too large
for Number). tuple hash then evaluated 'y & 0xFFFFFFFF' and frozenset hash
'_h << 16', raising 'Cannot mix BigInt and other types' (breaks
functools.lru_cache keys containing big ints). Reduce bigint element
hashes with BigInt.asIntN(32, ...) before Number mixing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
  • Loading branch information
zalo and claude committed Aug 13, 2026
commit e10b562fd52c8770961d9109cf502ec692a1f37c
6 changes: 6 additions & 0 deletions www/src/py_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,12 @@ _b_.tuple.tp_hash = function(self) {
var x = 0x3456789
for (var i = 0, len = self.length; i < len; i++) {
var y = _b_.hash(self[i])
if (typeof y == 'bigint') {
// hash values above Number.MAX_SAFE_INTEGER are bigints (eg
// hash(2 ** 60)); reduce to 32 bits before mixing with Number
// arithmetic
y = Number(BigInt.asIntN(32, y))
}
x = c_mul(1000003, x) ^ y & 0xFFFFFFFF
}
return x
Expand Down
6 changes: 6 additions & 0 deletions www/src/py_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,12 @@ frozenset.tp_hash = function(self) {

for (var entry of set_iter_with_hash(self)) {
var _h = entry.hash
if (typeof _h == 'bigint') {
// hash values above Number.MAX_SAFE_INTEGER are bigints (eg
// hash(2 ** 60)); reduce to 32 bits before mixing with Number
// arithmetic
_h = Number(BigInt.asIntN(32, _h))
}
_hash ^= ((_h ^ 89869747) ^ (_h << 16)) * 3644798167
}

Expand Down