Update PyDict.c

This commit is contained in:
blueloveTH 2025-09-17 14:37:59 +08:00
parent 50db32f36e
commit e4a900dd88

View File

@ -651,10 +651,18 @@ bool dict_items__next__(int argc, py_Ref argv) {
return StopIteration(); return StopIteration();
} }
bool dict_items__len__(int argc, py_Ref argv) {
PY_CHECK_ARGC(1);
DictIterator* iter = py_touserdata(py_arg(0));
py_newint(py_retval(), iter->dict->length);
return true;
}
py_Type pk_dict_items__register() { py_Type pk_dict_items__register() {
py_Type type = pk_newtype("dict_iterator", tp_object, NULL, NULL, false, true); py_Type type = pk_newtype("dict_iterator", tp_object, NULL, NULL, false, true);
py_bindmagic(type, __iter__, pk_wrapper__self); py_bindmagic(type, __iter__, pk_wrapper__self);
py_bindmagic(type, __next__, dict_items__next__); py_bindmagic(type, __next__, dict_items__next__);
py_bindmagic(type, __len__, dict_items__len__);
return type; return type;
} }