From 898e94a1ebb224924776f4d5e77497a40302727f Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 15 Nov 2024 09:05:13 -0500 Subject: [PATCH] fix: another possible assert changed back to a conditional. --- CHANGES.rst | 3 ++- coverage/parser.py | 4 ++-- tests/test_parser.py | 12 ++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 509b232da..05627564c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,7 +23,8 @@ upgrading your version of coverage.py. Unreleased ---------- -Nothing yet. +- fix: ugh, the other assert from 7.6.5 can also be encountered in the wild, + so it's been restored to a conditional. Sorry for the churn. .. start-releases diff --git a/coverage/parser.py b/coverage/parser.py index e458b39c3..cbd0f508d 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -444,8 +444,8 @@ def _line_numbers(self) -> Iterable[TLineNo]: if line_incr >= 0x80: line_incr -= 0x100 line_num += line_incr - assert line_num != last_line_num, f"Oops: {self.code.co_name}@{line_num}" - yield line_num + if line_num != last_line_num: + yield line_num def _find_statements(self) -> Iterable[TLineNo]: """Find the statements in `self.code`. diff --git a/tests/test_parser.py b/tests/test_parser.py index 467f9cfc7..5c3042816 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -198,14 +198,22 @@ def test_fuzzed_double_parse(self) -> None: self.parse_text("]") def test_bug_1891(self) -> None: - # This code exercises a code path I thought was impossible. + # These examples exercise code paths I thought were impossible. parser = self.parse_text("""\ res = siblings( 'configure', **ca, ) """) - assert parser.exit_counts() == { 1:1 } + assert parser.exit_counts() == {1: 1} + parser = self.parse_text("""\ + def g2(): + try: + return 2 + finally: + return 3 + """) + assert parser.exit_counts() == {1: 1, 2: 1, 3: 1, 5: 1} class ExclusionParserTest(PythonParserTestBase):