diff --git a/CHANGES.rst b/CHANGES.rst index 1ecc69ef9..e349d5524 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,7 +23,10 @@ upgrading your version of coverage.py. Unreleased ---------- -Nothing yet. +- One of the new asserts from 7.6.5 caused problems in real projects, as + reported in `issue 1891`_. The assert has been removed. + +.. _issue 1891: https://github.com/nedbat/coveragepy/issues/1891 .. start-releases diff --git a/coverage/parser.py b/coverage/parser.py index 51dc6afe4..e458b39c3 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -437,14 +437,14 @@ def _line_numbers(self) -> Iterable[TLineNo]: byte_num = 0 for byte_incr, line_incr in zip(byte_increments, line_increments): if byte_incr: - assert line_num != last_line_num, f"Oops, {byte_incr = }, {line_incr = }" - yield line_num - last_line_num = line_num + if line_num != last_line_num: + yield line_num + last_line_num = line_num byte_num += byte_incr if line_incr >= 0x80: line_incr -= 0x100 line_num += line_incr - assert line_num != last_line_num + assert line_num != last_line_num, f"Oops: {self.code.co_name}@{line_num}" yield line_num def _find_statements(self) -> Iterable[TLineNo]: diff --git a/tests/test_parser.py b/tests/test_parser.py index 1b956151f..a8f8a11f7 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -197,6 +197,13 @@ def test_fuzzed_double_parse(self) -> None: with pytest.raises(NotPython, match=msg): self.parse_text("]") + def test_bug_1891(self) -> None: + # This code exercises a code path I thought was impossible. + parser = self.parse_text("""\ + res = siblings('configure', **ca) + """) + assert parser.exit_counts() == { 1:1 } + class ExclusionParserTest(PythonParserTestBase): """Tests for the exclusion code in PythonParser."""