This commit is contained in:
blueloveTH 2023-08-22 23:40:09 +08:00
parent 53ea790caf
commit 8c4ccaa240
2 changed files with 15 additions and 1 deletions

View File

@ -360,7 +360,9 @@ i64 VM::py_hash(PyObject* obj){
PyObject* ret = call_method(self, f); PyObject* ret = call_method(self, f);
return CAST(i64, ret); return CAST(i64, ret);
} }
// it flow reaches here, obj must not be the trivial `object` type // if it is trivial `object`, return PK_BITS
if(ti == &_all_types[tp_object]) return PK_BITS(obj);
// otherwise, we check if it has a custom __eq__ other than object.__eq__
bool has_custom_eq = false; bool has_custom_eq = false;
if(ti->m__eq__) has_custom_eq = true; if(ti->m__eq__) has_custom_eq = true;
else{ else{

View File

@ -845,6 +845,18 @@ try:
except TypeError: except TypeError:
pass pass
a = hash(object()) # object is hashable
a = hash(A()) # A is hashable
class B:
def __eq__(self, o): return True
try:
hash(B())
print('未能拦截错误, 在测试 B.__hash__')
exit(1)
except TypeError:
pass
# 未完全测试准确性----------------------------------------------- # 未完全测试准确性-----------------------------------------------
# 116: 1009: _vm->bind__repr__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj) { # 116: 1009: _vm->bind__repr__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj) {
# #####: 1010: MappingProxy& self = _CAST(MappingProxy&, obj); # #####: 1010: MappingProxy& self = _CAST(MappingProxy&, obj);