Ignore exclusions inside multiline strings#2180
Open
puneetdixit200 wants to merge 7 commits into
Open
Conversation
Add explicit coverage showing default ellipsis exclusion patterns inside single-line strings are ignored while real pragma comments on the same line still exclude.
nedbat
reviewed
Jun 28, 2026
| ltext, | ||
| ) | ||
| ) | ||
| if toktype == token.STRING and slineno != elineno: |
Member
There was a problem hiding this comment.
This doesn't seem right to me: This is saying that any lines that are part of a multi-line string won't be excluded. That's not taking into account what else is on those lines, or whether the multi-line string matched one of the exclusion rules.
For example, this test fails:
self.check_coverage(
"""\
a = 1
ignore_var = "2"
ignore_var = '''
3,4,5
'''
ignore_var = "6"
a = 7
""",
excludes=["ignore_var"],
lines=[1, 7],
)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
...Tests:
PYTHONWARNDEFAULTENCODING= /tmp/coveragepy-venv/bin/python -m pytest -q tests/test_coverage.py::ExcludeTest::test_default_ellipsis_exclusion_ignores_multiline_strings tests/test_coverage.py::ExcludeTest::test_default tests/test_parser.py::ExclusionParserTest::test_over_exclusion_bug1779PYTHONWARNDEFAULTENCODING= /tmp/coveragepy-venv/bin/python -m pytest -q tests/test_coverage.py::ExcludeTestPYTHONWARNDEFAULTENCODING= /tmp/coveragepy-venv/bin/python -m pytest -q tests/test_parser.py::ExclusionParserTest/tmp/coveragepy-venv/bin/python -m compileall -q coverage/parser.py tests/test_coverage.pygit diff --checkSupersedes #2177
Fixes #2112