Skip to content

Commit 98939c9

Browse files
committed
fix: this assert is possible, remove it. #1891
1 parent ad4a4ff commit 98939c9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Diff for: CHANGES.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26-
Nothing yet.
26+
- One of the new asserts from 7.6.5 caused problems in real projects, as
27+
reported in `issue 1891`_. The assert has been removed.
28+
29+
.. _issue 1891: https://github.com/nedbat/coveragepy/issues/1891
2730

2831

2932
.. start-releases

Diff for: coverage/parser.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,14 @@ def _line_numbers(self) -> Iterable[TLineNo]:
437437
byte_num = 0
438438
for byte_incr, line_incr in zip(byte_increments, line_increments):
439439
if byte_incr:
440-
assert line_num != last_line_num, f"Oops, {byte_incr = }, {line_incr = }"
441-
yield line_num
442-
last_line_num = line_num
440+
if line_num != last_line_num:
441+
yield line_num
442+
last_line_num = line_num
443443
byte_num += byte_incr
444444
if line_incr >= 0x80:
445445
line_incr -= 0x100
446446
line_num += line_incr
447-
assert line_num != last_line_num
447+
assert line_num != last_line_num, f"Oops: {self.code.co_name}@{line_num}"
448448
yield line_num
449449

450450
def _find_statements(self) -> Iterable[TLineNo]:

Diff for: tests/test_parser.py

+10
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ def test_fuzzed_double_parse(self) -> None:
197197
with pytest.raises(NotPython, match=msg):
198198
self.parse_text("]")
199199

200+
def test_bug_1891(self) -> None:
201+
# This code exercises a code path I thought was impossible.
202+
parser = self.parse_text("""\
203+
res = siblings(
204+
'configure',
205+
**ca,
206+
)
207+
""")
208+
assert parser.exit_counts() == { 1:1 }
209+
200210

201211
class ExclusionParserTest(PythonParserTestBase):
202212
"""Tests for the exclusion code in PythonParser."""

0 commit comments

Comments
 (0)