فهرست منبع

Merge branch 'main' of https://github.com/pocketpy/pocketpy

blueloveTH 1 سال پیش
والد
کامیت
7a145b6c02
8فایلهای تغییر یافته به همراه48 افزوده شده و 1 حذف شده
  1. 7 0
      docs/modules/itertools.md
  2. 0 0
      include/pocketpy/_generated.h
  3. 13 0
      python/itertools.py
  4. 2 0
      python/typing.py
  5. 1 0
      src/pocketpy.cpp
  6. 1 1
      src/vm.cpp
  7. 18 0
      tests/28_iter.py
  8. 6 0
      tests/86_itertools.py

+ 7 - 0
docs/modules/itertools.md

@@ -0,0 +1,7 @@
+---
+icon: package
+label: itertools
+---
+
+### `itertools.zip_longest(a, b)`
+

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
include/pocketpy/_generated.h


+ 13 - 0
python/itertools.py

@@ -0,0 +1,13 @@
+def zip_longest(a, b):
+    a = iter(a)
+    b = iter(b)
+    while True:
+        ai = next(a)
+        bi = next(b)
+        if ai is StopIteration and bi is StopIteration:
+            break
+        if ai is StopIteration:
+            ai = None
+        if bi is StopIteration:
+            bi = None
+        yield ai, bi

+ 2 - 0
python/typing.py

@@ -32,6 +32,8 @@ LiteralString = _PLACEHOLDER
 Iterable = _PLACEHOLDER
 Generator = _PLACEHOLDER
 
+Hashable = _PLACEHOLDER
+
 TypeVar = _PLACEHOLDER
 Self = _PLACEHOLDER
 

+ 1 - 0
src/pocketpy.cpp

@@ -1622,6 +1622,7 @@ void VM::post_init(){
     _lazy_modules["typing"] = kPythonLibs_typing;
     _lazy_modules["datetime"] = kPythonLibs_datetime;
     _lazy_modules["cmath"] = kPythonLibs_cmath;
+    _lazy_modules["itertools"] = kPythonLibs_itertools;
 
     try{
         CodeObject_ code = compile(kPythonLibs_builtins, "<builtins>", EXEC_MODE);

+ 1 - 1
src/vm.cpp

@@ -729,7 +729,7 @@ void VM::init_builtin_types(){
     this->Ellipsis = heap._new<Dummy>(_new_type_object("ellipsis"));
     this->True = heap._new<Dummy>(tp_bool);
     this->False = heap._new<Dummy>(tp_bool);
-    this->StopIteration = heap._new<Dummy>(_new_type_object("StopIterationType"));
+    this->StopIteration = _all_types[_new_type_object("StopIteration", tp_exception)].obj;
 
     this->builtins = new_module("builtins");
     

+ 18 - 0
tests/28_iter.py

@@ -36,3 +36,21 @@ assert next(i) == 4
 assert next(i) == 5
 assert next(i) == StopIteration
 assert next(i) == StopIteration
+
+import builtins
+
+def next(obj):
+    res = builtins.next(obj)
+    if res is StopIteration:
+        raise StopIteration
+    return res
+    
+a = iter([1])
+assert next(a) == 1
+
+try:
+    next(a)
+    exit(1)
+except StopIteration:
+    pass
+

+ 6 - 0
tests/86_itertools.py

@@ -0,0 +1,6 @@
+from itertools import zip_longest
+
+a = [1, 2, 3]
+b = [2]
+
+assert list(zip_longest(a, b)) == [(1, 2), (2, None), (3, None)]

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است