From eddde8a16201803ac0b7d981d861a2f30a340875 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 14 Nov 2024 21:29:12 -0500 Subject: [PATCH] fix: this assert is possible, remove it. #1891 --- CHANGES.rst | 5 ++++- coverage/parser.py | 8 ++++---- tests/test_parser.py | 7 +++++++ 3 files changed, 15 insertions(+), 5 deletions(-) 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..e617133fb 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}@{linenum}" 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."""