Skip to content

Commit 0482302

Browse files
committed
Python 3.10 doesn't compile statments after unconditional jumps.
This includes break/continue/return/raise.
1 parent 92dae9e commit 0482302

File tree

3 files changed

+123
-89
lines changed

3 files changed

+123
-89
lines changed

coverage/env.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ class PYBEHAVIOR(object):
8585
# Python 3.9a1 made sys.argv[0] and other reported files absolute paths.
8686
report_absolute_files = (PYVERSION >= (3, 9))
8787

88+
# Lines after break/continue/return/raise are no longer compiled into the
89+
# bytecode. They used to be marked as missing, now they aren't executable.
90+
omit_after_jump = pep626
91+
92+
# PyPy has always omitted statements after return.
93+
omit_after_return = omit_after_jump or PYPY
94+
8895
# Coverage.py specifics.
8996

9097
# Are we using the C-implemented trace function?

tests/test_arcs.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,24 +215,40 @@ def test_nested_loop(self):
215215
)
216216

217217
def test_break(self):
218+
if env.PYBEHAVIOR.omit_after_jump:
219+
arcz = ".1 12 23 35 15 5."
220+
arcz_missing = "15"
221+
else:
222+
arcz = ".1 12 23 35 15 41 5."
223+
arcz_missing = "15 41"
224+
218225
self.check_coverage("""\
219226
for i in range(10):
220227
a = i
221228
break # 3
222229
a = 99
223230
assert a == 0 # 5
224231
""",
225-
arcz=".1 12 23 35 15 41 5.", arcz_missing="15 41")
232+
arcz=arcz, arcz_missing=arcz_missing
233+
)
226234

227235
def test_continue(self):
236+
if env.PYBEHAVIOR.omit_after_jump:
237+
arcz = ".1 12 23 31 15 5."
238+
arcz_missing = ""
239+
else:
240+
arcz = ".1 12 23 31 15 41 5."
241+
arcz_missing = "41"
242+
228243
self.check_coverage("""\
229244
for i in range(10):
230245
a = i
231246
continue # 3
232247
a = 99
233248
assert a == 9 # 5
234249
""",
235-
arcz=".1 12 23 31 15 41 5.", arcz_missing="41")
250+
arcz=arcz, arcz_missing=arcz_missing
251+
)
236252

237253
def test_nested_breaks(self):
238254
self.check_coverage("""\
@@ -495,6 +511,14 @@ def test_try_except(self):
495511
assert a == 3 and b == 1
496512
""",
497513
arcz=".1 12 23 36 45 56 6.", arcz_missing="45 56")
514+
515+
def test_raise_followed_by_statement(self):
516+
if env.PYBEHAVIOR.omit_after_jump:
517+
arcz = ".1 12 23 34 46 67 78 8."
518+
arcz_missing = ""
519+
else:
520+
arcz = ".1 12 23 34 46 58 67 78 8."
521+
arcz_missing = "58"
498522
self.check_coverage("""\
499523
a, b = 1, 1
500524
try:
@@ -505,8 +529,7 @@ def test_try_except(self):
505529
b = 7
506530
assert a == 3 and b == 7
507531
""",
508-
arcz=".1 12 23 34 46 58 67 78 8.",
509-
arcz_missing="58",
532+
arcz=arcz, arcz_missing=arcz_missing,
510533
)
511534

512535
def test_hidden_raise(self):
@@ -579,15 +602,15 @@ def test_try_finally(self):
579602
try:
580603
a = 4
581604
raise Exception("Yikes!")
582-
a = 6
605+
# line 6
583606
finally:
584607
c = 8
585608
except:
586609
d = 10 # A
587610
assert a == 4 and c == 8 and d == 10 # B
588611
""",
589-
arcz=".1 12 23 34 45 58 68 89 8B 9A AB B.",
590-
arcz_missing="68 8B",
612+
arcz=".1 12 23 34 45 58 89 9A AB B.",
613+
arcz_missing="",
591614
)
592615

593616
def test_finally_in_loop(self):

0 commit comments

Comments
 (0)