diff options
author | Mark Shannon <mark@hotpy.org> | 2021-04-30 13:32:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 13:32:47 (GMT) |
commit | 5979e81a212949c62c2490167c9137d233d7de64 (patch) | |
tree | f59b6fd4cb8420052b3783ddf460c2932b529c67 /Python/compile.c | |
parent | 64141382ecbad665d5738ff26d15505f3427c724 (diff) | |
download | cpython-5979e81a212949c62c2490167c9137d233d7de64.zip cpython-5979e81a212949c62c2490167c9137d233d7de64.tar.gz cpython-5979e81a212949c62c2490167c9137d233d7de64.tar.bz2 |
bpo-43933: Set frame.f_lineno during call to __exit__ (GH-25719)
* Set line number of __exit__ call in a with statement to be that of the with keyword.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index 6560fd4..4411edb 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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: @@ -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); @@ -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: @@ -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; } @@ -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); @@ -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); @@ -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; } @@ -5112,6 +5116,7 @@ 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); @@ -5119,7 +5124,6 @@ compiler_with(struct compiler *c, stmt_ty s, int pos) /* For exceptional outcome: */ compiler_use_next_block(c, final); - ADDOP(c, WITH_EXCEPT_START); compiler_with_except_finish(c); |