Commits

Ned Batchelder committed 3698df0

More yieldification of parser.py

  • Participants
  • Parent commits 30e88f7

Comments (0)

Files changed (2)

File coverage/parser.py

 import opcode, re, sys, token, tokenize
 
 from coverage.backward import set, sorted, StringIO # pylint: disable=W0622
-from coverage.backward import open_source
+from coverage.backward import open_source, range    # pylint: disable=W0622
 from coverage.bytecode import ByteCodes, CodeObjects
 from coverage.misc import nice_pair, expensive, join_regex
 from coverage.misc import CoverageException, NoSource, NotPython
                 # (a trick from trace.py in the stdlib.) This works for
                 # 99.9999% of cases.  For the rest (!) see:
                 # http://stackoverflow.com/questions/1769332/x/1769794#1769794
-                for i in range(slineno, elineno+1):
-                    self.docstrings.add(i)
+                self.docstrings.update(range(slineno, elineno+1))
             elif toktype == token.NEWLINE:
                 if first_line is not None and elineno != first_line:
                     # We're at the end of a line, and we've ended on a
     # Getting numbers from the lnotab value changed in Py3.0.
     if sys.version_info >= (3, 0):
         def _lnotab_increments(self, lnotab):
-            """Return a list of ints from the lnotab bytes in 3.x"""
-            return list(lnotab)
+            """Produce ints from the lnotab bytes in 3.x"""
+            # co_lnotab is a bytes object, which iterates as ints.
+            return lnotab
     else:
         def _lnotab_increments(self, lnotab):
-            """Return a list of ints from the lnotab string in 2.x"""
-            return [ord(c) for c in lnotab]
+            """Produce ints from the lnotab string in 2.x"""
+            for c in lnotab:
+                yield ord(c)
 
     def _bytes_lines(self):
         """Map byte offsets to line numbers in `code`.
     def _find_statements(self):
         """Find the statements in `self.code`.
 
-        Return a set of line numbers that start statements.  Recurses into all
-        code objects reachable from `self.code`.
+        Produce a sequence of line numbers that start statements.  Recurses
+        into all code objects reachable from `self.code`.
 
         """
-        stmts = set()
         for bp in self.child_parsers():
             # Get all of the lineno information from this code.
             for _, l in bp._bytes_lines():
-                stmts.add(l)
-        return stmts
+                yield l
 
     def _split_into_chunks(self):
         """Split the code object into a list of `Chunk` objects.
             byte_lines[byte_to_add] = lines
 
         # Figure out for each chunk where the exits go.
-        arcs = set()
         for chunk in chunks:
             if chunk.line:
                 for ex in chunk.exits:
                         exit_lines = byte_lines[ex]
                     for exit_line in exit_lines:
                         if chunk.line != exit_line:
-                            arcs.add((chunk.line, exit_line))
+                            yield (chunk.line, exit_line)
         for line in byte_lines[0]:
-            arcs.add((-1, line))
-
-        return arcs
+            yield (-1, line)
 
     def _all_chunks(self):
         """Returns a list of `Chunk` objects for this code and its children.

File doc/changes.rst

 
 - Added a page to the docs about :doc:`contributing <contributing>` to
   coverage.py, closing `issue 171`_.
-  
+
 - Added a page to the docs about :doc:`troublesome situations <trouble>`,
   closing `issue 226`_.
-  
+
 - Docstrings for the legacy singleton methods are more helpful.  Thanks Marius
   Gedminas.  Closes `issue 205`_.