Kaynağa Gözat

archive: closely wrap next() called from generator

lgtm:
Calling next() in a generator may cause unintended early termination of
an iteration.

It seems that lgtm did not detect the more loose wrapping that we used
before.
Thomas Waldmann 8 yıl önce
ebeveyn
işleme
199f192a65
1 değiştirilmiş dosya ile 4 ekleme ve 4 silme
  1. 4 4
      src/borg/archive.py

+ 4 - 4
src/borg/archive.py

@@ -172,11 +172,11 @@ backup_io = BackupIO()
 def backup_io_iter(iterator):
 def backup_io_iter(iterator):
     backup_io.op = 'read'
     backup_io.op = 'read'
     while True:
     while True:
-        try:
-            with backup_io:
+        with backup_io:
+            try:
                 item = next(iterator)
                 item = next(iterator)
-        except StopIteration:
-            return
+            except StopIteration:
+                return
         yield item
         yield item