Skip to content

Don't exclude a statement because of ... inside a string - #2329

Open
Kayvan-Zahiri wants to merge 4 commits into
coveragepy:mainfrom
Kayvan-Zahiri:fix/ellipsis-in-string-2112
Open

Kayvan-Zahiri wants to merge 4 commits into
coveragepy:mainfrom
Kayvan-Zahiri:fix/ellipsis-in-string-2112

Conversation

@Kayvan-Zahiri

@Kayvan-Zahiri Kayvan-Zahiri commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2112.

The default ... exclusion is meant to drop a line that is only an ellipsis, and a function whose body is only .... It also matched a line of three dots inside a multi-line string. A YAML literal that ends with ... was then excluded as a whole, so the assignment never showed up in the report.

An exclusion match is now ignored when its whole line sits inside a string literal (including f-string and t-string text), so a line with no code on it can't exclude the statement. A match on a line that also has code still counts, so exclude_lines = foo still excludes t = "foo is ignored", as test_lcov.py::test_excluded_lines expects. A real ... statement and a stub such as def stub(): ... are still excluded.

Test plan

  • tests/test_coverage.py::ExcludeTest::test_ellipsis_inside_string_is_not_excluded failed before the change: the YAML, f-string, and bytes assignments were missing from the measured lines ([6, 11, 15, 17] instead of [1, 6, 8, 11, 12, 15, 17]).
  • The same test passes after the change.
  • ExcludeTest and tests/test_parser.py: 104 passed, 1 skipped.

Made with Cursor

Kayvan-Zahiri and others added 4 commits October 8, 2026 17:10
The default ellipsis exclusion treated a line of three dots inside a
multi-line string as a stub body and dropped the whole assignment.

Co-authored-by: Cursor <[email protected]>
Skipping every match inside a string changed documented behavior:
exclude_lines = foo still has to exclude t = "foo ...", as
test_lcov.py::test_excluded_lines checks. A line with no code on it,
like the YAML ... marker in coveragepy#2112, is skipped; a code line is not.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default ... exclusion can exclude things by accident

1 participant