Incorrect coverage on continue statement

Issue #254 duplicate
Andrew Svetlov created an issue

When I've tried to make coverage for code like this:

def f(a):
    while True:
        a -= 1
        if a==0:


I'd got report that line with continue statement is never executed. That's definitely not true.

I used branched coverage: coverage3 run --branch coverage3 html

I'd got this problem when had worked on tulip, minimal stripped example that I published can reproduce error easy. Looks like tracer actually has never called with line for 'continue', that's how python works.


Comments (2)

  1. Ned Batchelder repo owner

    Andrew, unfortunately this is an artifact of the peephole optimizer.

    If you believe as I do that it would be useful to have a way to disable the peephole optimizer so that these sorts of analyses would give useful results, comment on this CPython ticket: "Add mechanism to disable optimizations".

  2. Log in to comment