File: fix-py37-breaking-changes-around-iterators.patch

package info (click to toggle)
blockdiag 1.5.3%2Bdfsg-5.2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,664 kB
  • sloc: python: 8,535; makefile: 13; sh: 1
file content (74 lines) | stat: -rw-r--r-- 2,043 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Description: Python 3.7 compatibility
 See PEP 479 for the breaking changes around iterators, based on
 serhiy-storchaka's suggestions for myitertools.py changes.
 Fixes #93
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Sun, 8 Jul 2018 17:46:06 +0200
Origin: https://github.com/blockdiag/blockdiag/pull/94
Last-Update: 2018-07-16

diff --git a/src/blockdiag/utils/myitertools.py b/src/blockdiag/utils/myitertools.py
index 364cc5c..6f7386e 100644
--- a/src/blockdiag/utils/myitertools.py
+++ b/src/blockdiag/utils/myitertools.py
@@ -14,33 +14,40 @@
 #  limitations under the License.
 
 from itertools import cycle
+from itertools import islice
 
 
 def istep(seq, step=2):
     iterable = iter(seq)
     while True:
-        yield [next(iterable) for _ in range(step)]
+        item = list(islice(iterable, step))
+        if len(item) < step:
+            break
+        yield item
 
 
 def stepslice(iterable, steps):
-    iterable = iter(iterable)
-    step = cycle(steps)
+    try:
+        iterable = iter(iterable)
+        step = cycle(steps)
 
-    while True:
-        # skip (1)
-        n = next(step)
-        if n == 0:
-            pass
-        elif n == 1:
-            o = next(iterable)
-            yield o
-            yield o
-        else:
-            yield next(iterable)
-            for _ in range(n - 2):
-                next(iterable)
-            yield next(iterable)
+        while True:
+            # skip (1)
+            n = next(step)
+            if n == 0:
+                pass
+            elif n == 1:
+                o = next(iterable)
+                yield o
+                yield o
+            else:
+                yield next(iterable)
+                for _ in range(n - 2):
+                    next(iterable)
+                yield next(iterable)
 
-        # skip (2)
-        for _ in range(next(step)):
-            next(iterable)
+            # skip (2)
+            for _ in range(next(step)):
+                next(iterable)
+    except StopIteration:
+        return