Skip to content

annotate: does not handle if False properly / consistently #659

Open
@nedbat

Description

@nedbat

Originally reported by Anonymous


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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    annotatebugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions