Support excluding multiline regexes (fix #996) by devdanzin · Pull Request #1807 · nedbat/coveragepy (original) (raw)

This PR allows using multiline regexes in exclude_lines. It does so by matching regexes against the whole source code, instead of line by line as was done before.

The behavior is equivalent to adding a # pragma: no cover comment to each line matched by the multiline regex. Because of that, if a suite (e.g. if True:) is matched, all statements inside it will also be excluded, just like if there was a no-cover pragma on the suite line.

This is made possible because @nedbat figured out a O(N) algorithm for finding line numbers for the matches. With it, there's a small performance increase for excluding lines compared to the previous code.

Fixes #996.