blueloveTH 5 mesi fa
parent
commit
e4a900dd88
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 8 0
      src/public/PyDict.c

+ 8 - 0
src/public/PyDict.c

@@ -651,10 +651,18 @@ bool dict_items__next__(int argc, py_Ref argv) {
     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 type = pk_newtype("dict_iterator", tp_object, NULL, NULL, false, true);
     py_bindmagic(type, __iter__, pk_wrapper__self);
     py_bindmagic(type, __next__, dict_items__next__);
+    py_bindmagic(type, __len__, dict_items__len__);
     return type;
 }