Commits

Ned Batchelder committed 6eb2a80

enumerate has a start parameter!

Comments (0)

Files changed (4)

 
         lines = []
 
-        for lineno, line in enumerate(source_token_lines(source)):
-            lineno += 1     # 1-based line numbers.
+        for lineno, line in enumerate(source_token_lines(source), start=1):
             # Figure out how to mark this line.
             line_class = []
             annotate_html = ""

coverage/parser.py

         """
         regex_c = re.compile(join_regex(regexes))
         matches = set()
-        for i, ltext in enumerate(self.lines):
+        for i, ltext in enumerate(self.lines, start=1):
             if regex_c.search(ltext):
-                matches.add(i+1)
+                matches.add(i)
         return matches
 
     def _raw_parse(self):
         checked.add(fname)
 
         line = None
-        for n, line in enumerate(open(fname, "rb")):
+        for n, line in enumerate(open(fname, "rb"), start=1):
             if crlf:
                 if "\r" in line:
-                    print("%s@%d: CR found" % (fname, n+1))
+                    print("%s@%d: CR found" % (fname, n))
                     return
             if trail_white:
                 line = line[:-1]
                 if not crlf:
                     line = line.rstrip('\r')
                 if line.rstrip() != line:
-                    print("%s@%d: trailing whitespace found" % (fname, n+1))
+                    print("%s@%d: trailing whitespace found" % (fname, n))
                     return
 
         if line is not None and not line.strip():
 
                 exit_counts = cp.exit_counts()
 
-                for i, ltext in enumerate(cp.lines):
-                    lineno = i+1
+                for lineno, ltext in enumerate(cp.lines, start=1):
                     m0 = m1 = m2 = m3 = a = ' '
                     if lineno in cp.statement_starts:
                         m0 = '-'