Skip to content

Commit

Permalink
fix: this assert is possible, remove it. #1891
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 15, 2024
1 parent ad4a4ff commit eddde8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions coverage/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit eddde8a

Please sign in to comment.