check-code: flag 0/1 used as constant Boolean expression
authorMartin Geisler <mg@lazybytes.net>
Wed, 01 Jun 2011 12:38:46 +0200
changeset 14494 1ffeeb91c55d
parent 14493 5cc7905bccc9
child 14495 ad6ad51cc0dd
check-code: flag 0/1 used as constant Boolean expression
contrib/check-code.py
contrib/perf.py
hgext/convert/cvs.py
hgext/zeroconf/Zeroconf.py
mercurial/ancestor.py
mercurial/bundlerepo.py
mercurial/changegroup.py
mercurial/commands.py
mercurial/copies.py
mercurial/hgweb/protocol.py
mercurial/keepalive.py
mercurial/localrepo.py
mercurial/lock.py
mercurial/patch.py
mercurial/revlog.py
mercurial/sshrepo.py
tests/md5sum.py
tests/tinyproxy.py
--- a/contrib/check-code.py	Tue May 31 20:39:04 2011 -0500
+++ b/contrib/check-code.py	Wed Jun 01 12:38:46 2011 +0200
@@ -163,6 +163,8 @@
     (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"),
     (r' [=!]=\s+(True|False|None)',
      "comparison with singleton, use 'is' or 'is not' instead"),
+    (r'^\s*(while|if) [01]:',
+     "use True/False for constant Boolean expression"),
     (r'opener\([^)]*\).read\(',
      "use opener.read() instead"),
     (r'opener\([^)]*\).write\(',
--- a/contrib/perf.py	Tue May 31 20:39:04 2011 -0500
+++ b/contrib/perf.py	Wed Jun 01 12:38:46 2011 +0200
@@ -8,7 +8,7 @@
     results = []
     begin = time.time()
     count = 0
-    while 1:
+    while True:
         ostart = os.times()
         cstart = time.time()
         r = func()
--- a/hgext/convert/cvs.py	Tue May 31 20:39:04 2011 -0500
+++ b/hgext/convert/cvs.py	Wed Jun 01 12:38:46 2011 +0200
@@ -227,7 +227,7 @@
 
         data = ""
         mode = None
-        while 1:
+        while True:
             line = self.readp.readline()
             if line.startswith("Created ") or line.startswith("Updated "):
                 self.readp.readline() # path
--- a/hgext/zeroconf/Zeroconf.py	Tue May 31 20:39:04 2011 -0500
+++ b/hgext/zeroconf/Zeroconf.py	Wed Jun 01 12:38:46 2011 +0200
@@ -591,7 +591,7 @@
 		next = -1
 		first = off
 
-		while 1:
+		while True:
 			len = ord(self.data[off])
 			off += 1
 			if len == 0:
@@ -939,7 +939,7 @@
 		self.start()
 
 	def run(self):
-		while 1:
+		while True:
 			self.zeroconf.wait(10 * 1000)
 			if globals()['_GLOBAL_DONE']:
 				return
@@ -1003,7 +1003,7 @@
 		self.zeroconf.notifyAll()
 
 	def run(self):
-		while 1:
+		while True:
 			event = None
 			now = currentTimeMillis()
 			if len(self.list) == 0 and self.nextTime > now:
--- a/mercurial/ancestor.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/ancestor.py	Wed Jun 01 12:38:46 2011 +0200
@@ -76,7 +76,7 @@
     # increment each ancestor list until it is closer to root than
     # the other, or they match
     try:
-        while 1:
+        while True:
             if gx[0] == gy[0]:
                 for v in gx[1]:
                     if v in gy[1]:
--- a/mercurial/bundlerepo.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/bundlerepo.py	Wed Jun 01 12:38:46 2011 +0200
@@ -33,7 +33,7 @@
         self.basemap = {}
         n = len(self)
         chain = None
-        while 1:
+        while True:
             chunkdata = bundle.deltachunk(chain)
             if not chunkdata:
                 break
@@ -185,7 +185,7 @@
 
             try:
                 fptemp.write("HG10UN")
-                while 1:
+                while True:
                     chunk = self.bundle.read(2**18)
                     if not chunk:
                         break
@@ -232,13 +232,13 @@
     def file(self, f):
         if not self.bundlefilespos:
             self.bundle.seek(self.filestart)
-            while 1:
+            while True:
                 chunkdata = self.bundle.filelogheader()
                 if not chunkdata:
                     break
                 fname = chunkdata['filename']
                 self.bundlefilespos[fname] = self.bundle.tell()
-                while 1:
+                while True:
                     c = self.bundle.deltachunk(None)
                     if not c:
                         break
--- a/mercurial/changegroup.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/changegroup.py	Wed Jun 01 12:38:46 2011 +0200
@@ -91,7 +91,7 @@
         while not empty or count <= 2:
             empty = True
             count += 1
-            while 1:
+            while True:
                 chunk = getchunk(cg)
                 if not chunk:
                     break
--- a/mercurial/commands.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/commands.py	Wed Jun 01 12:38:46 2011 +0200
@@ -1342,7 +1342,7 @@
             def showchunks(named):
                 ui.write("\n%s\n" % named)
                 chain = None
-                while 1:
+                while True:
                     chunkdata = gen.deltachunk(chain)
                     if not chunkdata:
                         break
@@ -1361,7 +1361,7 @@
             showchunks("changelog")
             chunkdata = gen.manifestheader()
             showchunks("manifest")
-            while 1:
+            while True:
                 chunkdata = gen.filelogheader()
                 if not chunkdata:
                     break
@@ -1370,7 +1370,7 @@
         else:
             chunkdata = gen.changelogheader()
             chain = None
-            while 1:
+            while True:
                 chunkdata = gen.deltachunk(chain)
                 if not chunkdata:
                     break
--- a/mercurial/copies.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/copies.py	Wed Jun 01 12:38:46 2011 +0200
@@ -134,7 +134,7 @@
             if f2r is None:
                 f2 = g2.next()
 
-            while 1:
+            while True:
                 f1r, f2r = f1.rev(), f2.rev()
                 if f1r > f2r:
                     f1 = g1.next()
--- a/mercurial/hgweb/protocol.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/hgweb/protocol.py	Wed Jun 01 12:38:46 2011 +0200
@@ -33,7 +33,7 @@
         args = self.req.form.copy()
         chunks = []
         i = 1
-        while 1:
+        while True:
             h = self.req.env.get('HTTP_X_HGARG_' + str(i))
             if h is None:
                 break
@@ -50,7 +50,7 @@
         sys.stderr = sys.stdout = cStringIO.StringIO()
     def groupchunks(self, cg):
         z = zlib.compressobj()
-        while 1:
+        while True:
             chunk = cg.read(4096)
             if not chunk:
                 break
--- a/mercurial/keepalive.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/keepalive.py	Wed Jun 01 12:38:46 2011 +0200
@@ -507,7 +507,7 @@
     def readlines(self, sizehint = 0):
         total = 0
         list = []
-        while 1:
+        while True:
             line = self.readline()
             if not line:
                 break
@@ -654,7 +654,7 @@
 
     fo = urllib2.urlopen(url)
     foo = ''
-    while 1:
+    while True:
         f = fo.readline()
         if f:
             foo = foo + f
--- a/mercurial/localrepo.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/localrepo.py	Wed Jun 01 12:38:46 2011 +0200
@@ -1309,7 +1309,7 @@
         b = []
         for n in nodes:
             t = n
-            while 1:
+            while True:
                 p = self.changelog.parents(n)
                 if p[1] != nullid or p[0] == nullid:
                     b.append((t, n, p[0], p[1]))
@@ -1777,7 +1777,7 @@
             pr.total = efiles
             source.callback = None
 
-            while 1:
+            while True:
                 chunkdata = source.filelogheader()
                 if not chunkdata:
                     break
--- a/mercurial/lock.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/lock.py	Wed Jun 01 12:38:46 2011 +0200
@@ -51,7 +51,7 @@
 
     def lock(self):
         timeout = self.timeout
-        while 1:
+        while True:
             try:
                 self.trylock()
                 return 1
--- a/mercurial/patch.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/patch.py	Wed Jun 01 12:38:46 2011 +0200
@@ -346,7 +346,7 @@
         return self.fp.readline()
 
     def __iter__(self):
-        while 1:
+        while True:
             l = self.readline()
             if not l:
                 break
--- a/mercurial/revlog.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/revlog.py	Wed Jun 01 12:38:46 2011 +0200
@@ -1151,7 +1151,7 @@
         try:
             # loop through our set of deltas
             chain = None
-            while 1:
+            while True:
                 chunkdata = bundle.deltachunk(chain)
                 if not chunkdata:
                     break
--- a/mercurial/sshrepo.py	Tue May 31 20:39:04 2011 -0500
+++ b/mercurial/sshrepo.py	Wed Jun 01 12:38:46 2011 +0200
@@ -88,7 +88,7 @@
                 break
 
     def readerr(self):
-        while 1:
+        while True:
             size = util.fstat(self.pipee).st_size
             if size == 0:
                 break
@@ -148,7 +148,7 @@
         r = self._call(cmd, **args)
         if r:
             return '', r
-        while 1:
+        while True:
             d = fp.read(4096)
             if not d:
                 break
@@ -193,7 +193,7 @@
         d = self._call("addchangegroup")
         if d:
             self._abort(error.RepoError(_("push refused: %s") % d))
-        while 1:
+        while True:
             d = cg.read(4096)
             if not d:
                 break
--- a/tests/md5sum.py	Tue May 31 20:39:04 2011 -0500
+++ b/tests/md5sum.py	Wed Jun 01 12:38:46 2011 +0200
@@ -29,7 +29,7 @@
 
     m = md5()
     try:
-        while 1:
+        while True:
             data = fp.read(8192)
             if not data:
                 break
--- a/tests/tinyproxy.py	Tue May 31 20:39:04 2011 -0500
+++ b/tests/tinyproxy.py	Wed Jun 01 12:38:46 2011 +0200
@@ -95,7 +95,7 @@
         iw = [self.connection, soc]
         ow = []
         count = 0
-        while 1:
+        while True:
             count += 1
             (ins, _, exs) = select.select(iw, ow, iw, 3)
             if exs: