summaryrefslogtreecommitdiff
path: root/coverage/parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-01-09 20:49:51 -0500
committerNed Batchelder <ned@nedbatchelder.com>2013-01-09 20:49:51 -0500
commit4b69792c3f51d3f9f990ea3dd0bbe89138cdecae (patch)
tree9c6b098e159dea9e195f0bd6aefe97315a54e0a8 /coverage/parser.py
parent1da4388377f1aad1b1552d9b01ca10ce26f9e1dc (diff)
downloadpython-coveragepy-4b69792c3f51d3f9f990ea3dd0bbe89138cdecae.tar.gz
Use the nice way to reverse a list.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r--coverage/parser.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index 73c629a..da4fc8b 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -4,6 +4,7 @@ import opcode, re, sys, token, tokenize
from coverage.backward import set, sorted, StringIO # pylint: disable=W0622
from coverage.backward import open_source, range # pylint: disable=W0622
+from coverage.backward import reversed # 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
@@ -384,6 +385,9 @@ class ByteParser(object):
Uses co_lnotab described in Python/compile.c to map byte offsets to
line numbers. Produces a sequence: (b0, l0), (b1, l1), ...
+ Only byte offsets that correspond to line numbers are included in the
+ results.
+
"""
# Adapted from dis.py in the standard library.
byte_increments = self._lnotab_increments(self.code.co_lnotab[0::2])
@@ -426,6 +430,8 @@ class ByteParser(object):
# The list of chunks so far, and the one we're working on.
chunks = []
chunk = None
+
+ # A dict mapping byte offsets of line starts to the line numbers.
bytes_lines_map = dict(self._bytes_lines())
# The block stack: loops and try blocks get pushed here for the
@@ -492,9 +498,9 @@ class ByteParser(object):
chunk.exits.add(block_stack[-1][1])
# For the finally clause we need to find the closest exception
# block, and use its jump target as an exit.
- for iblock in range(len(block_stack)-1, -1, -1):
- if block_stack[iblock][0] in OPS_EXCEPT_BLOCKS:
- chunk.exits.add(block_stack[iblock][1])
+ for block in reversed(block_stack):
+ if block[0] in OPS_EXCEPT_BLOCKS:
+ chunk.exits.add(block[1])
break
if bc.op == OP_COMPARE_OP and bc.arg == COMPARE_EXCEPTION:
# This is an except clause. We want to overlook the next