annotate: does not handle `if False` properly / consistently

Issue #659 closed
Former user created an issue

coverage annotate considers lines after if False to be covered:

% python -m coverage run t.py && python -m coverage annotate t.py && python -m coverage report -m && cat t.py,cover
1
Name    Stmts   Miss  Cover   Missing
-------------------------------------
t.py        1      0   100%
> if False:
>     print('never')
> print(1)

I know that if False is a special case (optimization), but AnnotateReporter.annotate_file should handle it properly.

analysis.statements is [3] in this case, that's why the covered logic kicks in later only.

Since covered gets not updated for the if False, it will be considered to be uncovered in the following case, because the previous line sets covered=False:

1
Name    Stmts   Miss  Cover   Missing
-------------------------------------
t.py        4      1    75%   3
> a = 0
> if a:
!     print(0)
! if False:
!     print('never')
> print(1)

Comments (3)

  1. Log in to comment