mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
* Initial plan * Fix hash wrapper overflow handling Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com> * Auto-format: cargo fmt --all * Adjust __hash__ wrapper conversion Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com> * Auto-format: cargo fmt --all --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
31 lines
467 B
Python
31 lines
467 B
Python
from testutils import assert_raises
|
|
|
|
|
|
class A:
|
|
pass
|
|
|
|
|
|
assert type(hash(None)) is int
|
|
assert type(hash(object())) is int
|
|
assert type(hash(A())) is int
|
|
assert type(hash(1)) is int
|
|
assert type(hash(1.1)) is int
|
|
assert type(hash("")) is int
|
|
|
|
|
|
class Evil:
|
|
def __hash__(self):
|
|
return 1 << 63
|
|
|
|
|
|
assert hash(Evil()) == 4
|
|
|
|
with assert_raises(TypeError):
|
|
hash({})
|
|
|
|
with assert_raises(TypeError):
|
|
hash(set())
|
|
|
|
with assert_raises(TypeError):
|
|
hash([])
|