There is something special with the way how Cython treats conversion to Py_hash_t (as opposed to other C integer types). Usually, the appropriate __index__ (or __int__) method is called but this is not the case for Py_hash_t on Python 3: that requires an actual Python int. Also on Python 2, conversion to Py_hash_t works fine in all cases.
More precisely: this works on Python 2 and 3:
def to_int(x):
return <Py_ssize_t>x
class X(object):
def __index__(self): return 0
print(to_int(X()))
But this only works on Python 2:
def to_int(x):
return <Py_hash_t>x
class X(object):
def __index__(self): return 0
print(to_int(X()))
There is something special with the way how Cython treats conversion to
Py_hash_t(as opposed to other C integer types). Usually, the appropriate__index__(or__int__) method is called but this is not the case forPy_hash_ton Python 3: that requires an actual Pythonint. Also on Python 2, conversion toPy_hash_tworks fine in all cases.More precisely: this works on Python 2 and 3:
But this only works on Python 2: