Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_dis.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1087,7 +1087,7 @@ def jumpy():
Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=154, starts_line=None, is_jump_target=False),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=156, starts_line=None, is_jump_target=False),
Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=160, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=160, starts_line=25, is_jump_target=False),
Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False),
Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=164, starts_line=None, is_jump_target=False),
Instruction(opname='CALL_FUNCTION', opcode=131, arg=3, argval=3, argrepr='', offset=166, starts_line=None, is_jump_target=False),
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_sys_settrace.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -936,10 +936,11 @@ def func():
(-4, 'line'),
(-4, 'return'),
(2, 'line'),
(1, 'line'),
(-3, 'call'),
(-2, 'line'),
(-2, 'return'),
(2, 'return')])
(1, 'return')])

def test_if_false_in_try_except(self):

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Set frame.f_lineno to the line number of the 'with' kweyword when executing
the call to ``__exit__``.
12 changes: 8 additions & 4 deletions Python/compile.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -1745,6 +1745,7 @@ static int
compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
int preserve_tos)
{
int loc;
switch (info->fb_type) {
case WHILE_LOOP:
case EXCEPTION_HANDLER:
Expand DownExpand Up@@ -1797,6 +1798,8 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,

case WITH:
case ASYNC_WITH:
loc = c->u->u_lineno;
SET_LOC(c, (stmt_ty)info->fb_datum);
ADDOP(c, POP_BLOCK);
if (preserve_tos) {
ADDOP(c, ROT_TWO);
Expand All@@ -1810,6 +1813,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
ADDOP(c, YIELD_FROM);
}
ADDOP(c, POP_TOP);
c->u->u_lineno = loc;
return 1;

case HANDLER_CLEANUP:
Expand DownExpand Up@@ -4990,7 +4994,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)

/* SETUP_ASYNC_WITH pushes a finally block. */
compiler_use_next_block(c, block);
if (!compiler_push_fblock(c, ASYNC_WITH, block, final, NULL)) {
if (!compiler_push_fblock(c, ASYNC_WITH, block, final, s)) {
return 0;
}

Expand All@@ -5016,6 +5020,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
/* For successful outcome:
* call __exit__(None, None, None)
*/
SET_LOC(c, s);
if(!compiler_call_exit_with_nones(c))
return 0;
ADDOP(c, GET_AWAITABLE);
Expand All@@ -5028,7 +5033,6 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)

/* For exceptional outcome: */
compiler_use_next_block(c, final);

ADDOP(c, WITH_EXCEPT_START);
ADDOP(c, GET_AWAITABLE);
ADDOP_LOAD_CONST(c, Py_None);
Expand DownExpand Up@@ -5082,7 +5086,7 @@ compiler_with(struct compiler *c, stmt_ty s, int pos)

/* SETUP_WITH pushes a finally block. */
compiler_use_next_block(c, block);
if (!compiler_push_fblock(c, WITH, block, final, NULL)) {
if (!compiler_push_fblock(c, WITH, block, final, s)) {
return 0;
}

Expand DownExpand Up@@ -5112,14 +5116,14 @@ compiler_with(struct compiler *c, stmt_ty s, int pos)
/* For successful outcome:
* call __exit__(None, None, None)
*/
SET_LOC(c, s);
if (!compiler_call_exit_with_nones(c))
return 0;
ADDOP(c, POP_TOP);
ADDOP_JUMP(c, JUMP_FORWARD, exit);

/* For exceptional outcome: */
compiler_use_next_block(c, final);

ADDOP(c, WITH_EXCEPT_START);
compiler_with_except_finish(c);

Expand Down
Loading