Make Python builtin types hashable by default
Default hash is the underlying C/C++ pointer. This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare) which compares the pointers.
This commit is contained in:
parent
253a39fdff
commit
5b7c08c214
5 changed files with 53 additions and 16 deletions
|
|
@ -1,6 +1,17 @@
|
|||
from python_builtin import *
|
||||
|
||||
if is_python_builtin():
|
||||
# Test 0 for default tp_hash
|
||||
vs = ValueStruct(1234)
|
||||
h = hash(vs)
|
||||
d = dict()
|
||||
d[h] = "hi"
|
||||
if h not in d:
|
||||
raise RuntimeError("h should be in d")
|
||||
h2 = hash(ValueStruct.inout(vs))
|
||||
if h != h2:
|
||||
raise RuntimeError("default tp_hash not working")
|
||||
|
||||
# Test 1 for tp_hash
|
||||
if hash(SimpleValue(222)) != 222:
|
||||
raise RuntimeError("tp_hash not working")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue