blueloveTH 4 tygodni temu
rodzic
commit
d5b711f50c
3 zmienionych plików z 27 dodań i 10 usunięć
  1. 12 10
      python/builtins.py
  2. 0 0
      src/common/_generated.c
  3. 15 0
      tests/720_collections.py

+ 12 - 10
python/builtins.py

@@ -60,16 +60,18 @@ def filter(f, iterable):
         if f(i):
             yield i
 
-def zip(a, b):
-    a = iter(a)
-    b = iter(b)
-    while True:
-        try:
-            ai = next(a)
-            bi = next(b)
-        except StopIteration:
-            break
-        yield ai, bi
+class zip:
+    def __init__(self, *iterables):
+        self.iterables = [iter(it) for it in iterables]
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        result = []
+        for it in self.iterables:
+            result.append(next(it))
+        return tuple(result)
 
 def reversed(iterable):
     a = list(iterable)

Plik diff jest za duży
+ 0 - 0
src/common/_generated.c


+ 15 - 0
tests/720_collections.py

@@ -381,6 +381,21 @@ for x, y in zip(d, e):
     # verify that original order and values are retained.
     assertEqual(x is y, True)
 
+# https://github.com/pocketpy/pocketpy/issues/447
+names = ["Alice", "Bob", "Charlie"]
+ages = [25, 30, 35]
+cities = ["NY", "LA", "SF"]
+result = []
+for name, age, city in zip(names, ages, cities):
+    result.append((name, age, city))
+assertEqual(result, [("Alice", 25, "NY"), ("Bob", 30, "LA"), ("Charlie", 35, "SF")])
+
+cities.pop()
+result = []
+for name, age, city in zip(names, ages, cities):
+    result.append((name, age, city))
+assertEqual(result, [("Alice", 25, "NY"), ("Bob", 30, "LA")])
+
 ########### test repr#############
 d = deque(range(200))
 e = eval(repr(d))

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików