Skip to content

Commit 4c4eebc

Browse files
committed
fix location of POP_BLOCK
1 parent c8eb6bf commit 4c4eebc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Lib/test/test_listcomps.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,16 @@ def f(value):
586586
"""
587587
self._check_in_scopes(code, {"ret": ["a"]})
588588

589+
def test_exception_in_post_comp_call(self):
590+
code = """
591+
value = [1, None]
592+
try:
593+
[v for v in value].sort()
594+
except:
595+
pass
596+
"""
597+
self._check_in_scopes(code, {"value": [1, None]})
598+
589599

590600
__test__ = {'doctests' : doctests}
591601

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5690,6 +5690,7 @@ pop_inlined_comprehension_state(struct compiler *c, location loc,
56905690
PyObject *k, *v;
56915691
Py_ssize_t pos = 0;
56925692
if (IS_LABEL(state.cleanup)) {
5693+
ADDOP(c, NO_LOCATION, POP_BLOCK);
56935694
ADDOP_JUMP(c, NO_LOCATION, JUMP, state.end);
56945695

56955696
// cleanup from an exception inside the comprehension
@@ -5701,7 +5702,6 @@ pop_inlined_comprehension_state(struct compiler *c, location loc,
57015702
return ERROR;
57025703
}
57035704
ADDOP_I(c, NO_LOCATION, RERAISE, 0);
5704-
ADDOP(c, NO_LOCATION, POP_BLOCK);
57055705

57065706
USE_LABEL(c, state.end);
57075707
}

0 commit comments

Comments
 (0)