Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e2cded

Browse files
committed
Set the line number correctly for a nested function with an exec or
import *. Mark the offending stmt rather than the function def line.
1 parent 280e6bd commit 2e2cded

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Include/symtable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct _symtable_entry {
4646
int ste_nested; /* true if scope is nested */
4747
int ste_child_free; /* true if a child scope has free variables,
4848
including free refs to globals */
49+
int ste_opt_lineno; /* lineno of last exec or import * */
4950
struct symtable *ste_table;
5051
} PySymtableEntryObject;
5152

Python/compile.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,7 +4241,7 @@ symtable_check_unoptimized(struct compiling *c,
42414241
if (c->c_symtable->st_nested_scopes) {
42424242
PyErr_SetString(PyExc_SyntaxError, buf);
42434243
PyErr_SyntaxLocation(c->c_symtable->st_filename,
4244-
ste->ste_lineno);
4244+
ste->ste_opt_lineno);
42454245
return -1;
42464246
}
42474247
else {
@@ -4820,8 +4820,10 @@ symtable_node(struct symtable *st, node *n)
48204820
symtable_node(st, CHILD(n, 1));
48214821
if (NCH(n) > 2)
48224822
symtable_node(st, CHILD(n, 3));
4823-
else
4823+
else {
48244824
st->st_cur->ste_optimized |= OPT_BARE_EXEC;
4825+
st->st_cur->ste_opt_lineno = n->n_lineno;
4826+
}
48254827
if (NCH(n) > 4)
48264828
symtable_node(st, CHILD(n, 5));
48274829
break;
@@ -5106,6 +5108,7 @@ symtable_import(struct symtable *st, node *n)
51065108
}
51075109
if (TYPE(CHILD(n, 3)) == STAR) {
51085110
st->st_cur->ste_optimized |= OPT_IMPORT_STAR;
5111+
st->st_cur->ste_opt_lineno = n->n_lineno;
51095112
} else {
51105113
for (i = 3; i < NCH(n); i += 2) {
51115114
node *c = CHILD(n, i);

0 commit comments

Comments
 (0)