Skip to content

Commit 8eb95b5

Browse files
committed
fix: recent pypy3.9 now omits lines after jumps
We were seeing these failures in the nightly builds: ``` FAILED tests/test_arcs.py::LoopArcTest::test_continue - AssertionError: Possible arcs differ: minus is expected, plus is actual (-1, 1) # .1 (1, 2) # 12 (1, 5) # 15 (2, 3) # 23 (3, 1) # 31 - (4, 1) # 41 (5, -1) # 5. Missing arcs differ: minus is expected, plus is actual - (4, 1) # 41 + assert False FAILED tests/test_arcs.py::LoopArcTest::test_break - AssertionError: Possible arcs differ: minus is expected, plus is actual (-1, 1) # .1 (1, 2) # 12 (1, 5) # 15 (2, 3) # 23 (3, 5) # 35 - (4, 1) # 41 (5, -1) # 5. Missing arcs differ: minus is expected, plus is actual (1, 5) # 15 - (4, 1) # 41 assert False FAILED tests/test_arcs.py::ExceptionArcTest::test_raise_followed_by_statement - AssertionError: Possible arcs differ: minus is expected, plus is actual (-1, 1) # .1 (1, 2) # 12 (2, 3) # 23 (3, 4) # 34 (4, 6) # 46 - (5, 8) # 58 (6, 7) # 67 (7, 8) # 78 (8, -1) # 8. Missing arcs differ: minus is expected, plus is actual - (5, 8) # 58 + assert False FAILED tests/test_coverage.py::SimpleStatementTest::test_raise_followed_by_statement - AssertionError: [1, 2, 4, 5] != [1, 2, 3, 4, 5] assert [1, 2, 4, 5] == [1, 2, 3, 4, 5] At index 2 diff: 4 != 3 Right contains one more item: 5 Full diff: - [1, 2, 3, 4, 5] ? --- + [1, 2, 4, 5] FAILED tests/test_coverage.py::SimpleStatementTest::test_break - AssertionError: [1, 2, 3, 5] != [1, 2, 3, 4, 5] assert [1, 2, 3, 5] == [1, 2, 3, 4, 5] At index 3 diff: 5 != 4 Right contains one more item: 5 Full diff: - [1, 2, 3, 4, 5] ? --- + [1, 2, 3, 5] FAILED tests/test_coverage.py::SimpleStatementTest::test_continue - AssertionError: [1, 2, 3, 5] != [1, 2, 3, 4, 5] assert [1, 2, 3, 5] == [1, 2, 3, 4, 5] At index 3 diff: 5 != 4 Right contains one more item: 5 Full diff: - [1, 2, 3, 4, 5] ? --- + [1, 2, 3, 5] ```
1 parent d276fa4 commit 8eb95b5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

coverage/env.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,17 @@ class PYBEHAVIOR:
106106

107107
# Lines after break/continue/return/raise are no longer compiled into the
108108
# bytecode. They used to be marked as missing, now they aren't executable.
109-
omit_after_jump = pep626
109+
omit_after_jump = (
110+
pep626
111+
or (PYPY and PYVERSION >= (3, 9) and PYPYVERSION >= (7, 3, 12))
112+
)
110113

111114
# PyPy has always omitted statements after return.
112115
omit_after_return = omit_after_jump or PYPY
113116

117+
# Optimize away unreachable try-else clauses.
118+
optimize_unreachable_try_else = pep626
119+
114120
# Modules used to have firstlineno equal to the line number of the first
115121
# real line of code. Now they always start at 1.
116122
module_firstline_1 = pep626

tests/test_coverage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ def test_try_except(self) -> None:
11211121
)
11221122

11231123
def test_try_except_stranded_else(self) -> None:
1124-
if env.PYBEHAVIOR.omit_after_jump:
1124+
if env.PYBEHAVIOR.optimize_unreachable_try_else:
11251125
# The else can't be reached because the try ends with a raise.
11261126
lines = [1,2,3,4,5,6,9]
11271127
missing = ""
@@ -1498,7 +1498,7 @@ def test_excluding_try_except(self) -> None:
14981498
)
14991499

15001500
def test_excluding_try_except_stranded_else(self) -> None:
1501-
if env.PYBEHAVIOR.omit_after_jump:
1501+
if env.PYBEHAVIOR.optimize_unreachable_try_else:
15021502
# The else can't be reached because the try ends with a raise.
15031503
arcz = ".1 12 23 34 45 56 69 9."
15041504
arcz_missing = ""
@@ -1801,7 +1801,7 @@ def test_try_except_finally(self) -> None:
18011801
)
18021802

18031803
def test_try_except_finally_stranded_else(self) -> None:
1804-
if env.PYBEHAVIOR.omit_after_jump:
1804+
if env.PYBEHAVIOR.optimize_unreachable_try_else:
18051805
# The else can't be reached because the try ends with a raise.
18061806
lines = [1,2,3,4,5,6,10,11]
18071807
missing = ""

0 commit comments

Comments
 (0)