]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
rewrite asserts to be side-effect free
authorJon Dowland <jmtd@debian.org>
Wed, 16 May 2012 14:41:23 +0000 (15:41 +0100)
committerJon Dowland <jmtd@debian.org>
Thu, 24 May 2012 17:04:38 +0000 (18:04 +0100)
Two asserts changed program state, and so problems could occur if
the asserts are not executed (such as when PYTHONOPTIMIZE is fiddled
with). Move the side-effect code out of the assert and test only
previously calculated results.

lib/bup/git.py

index 5cb282922c392169dffc6bb9083ae441be606256..b999a098f25af164a282fd417ddb844cc59b6175 100644 (file)
@@ -959,7 +959,8 @@ class CatPipe:
         if not self.p or self.p.poll() != None:
             self._restart()
         assert(self.p)
-        assert(self.p.poll() == None)
+        r = self.p.poll()
+        assert(r == None)
         if self.inprogress:
             log('_fast_get: opening %r while %r is open\n'
                 % (id, self.inprogress))
@@ -985,7 +986,8 @@ class CatPipe:
             yield type
             for blob in it:
                 yield blob
-            assert(self.p.stdout.readline() == '\n')
+            l = self.p.stdout.readline()
+            assert(l == '\n')
             self.inprogress = None
         except Exception, e:
             it.abort()