mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
fix: dict
and mappingproxy
cannot be hashed
This commit is contained in:
parent
8eb01dc352
commit
38f5eb5bcf
@ -988,6 +988,11 @@ void init_builtins(VM* _vm) {
|
|||||||
return (i64)_CAST(MappingProxy&, obj).attr().size();
|
return (i64)_CAST(MappingProxy&, obj).attr().size();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_vm->bind__hash__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj) {
|
||||||
|
vm->TypeError("unhashable type: 'mappingproxy'");
|
||||||
|
return (i64)0;
|
||||||
|
});
|
||||||
|
|
||||||
_vm->bind__getitem__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj, PyObject* index) {
|
_vm->bind__getitem__(_vm->tp_mappingproxy, [](VM* vm, PyObject* obj, PyObject* index) {
|
||||||
MappingProxy& self = _CAST(MappingProxy&, obj);
|
MappingProxy& self = _CAST(MappingProxy&, obj);
|
||||||
StrName key = CAST(Str&, index);
|
StrName key = CAST(Str&, index);
|
||||||
@ -1044,6 +1049,11 @@ void init_builtins(VM* _vm) {
|
|||||||
return (i64)_CAST(Dict&, obj).size();
|
return (i64)_CAST(Dict&, obj).size();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_vm->bind__hash__(_vm->tp_dict, [](VM* vm, PyObject* obj) {
|
||||||
|
vm->TypeError("unhashable type: 'dict'");
|
||||||
|
return (i64)0;
|
||||||
|
});
|
||||||
|
|
||||||
_vm->bind__getitem__(_vm->tp_dict, [](VM* vm, PyObject* obj, PyObject* index) {
|
_vm->bind__getitem__(_vm->tp_dict, [](VM* vm, PyObject* obj, PyObject* index) {
|
||||||
Dict& self = _CAST(Dict&, obj);
|
Dict& self = _CAST(Dict&, obj);
|
||||||
PyObject* ret = self.try_get(index);
|
PyObject* ret = self.try_get(index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user