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

Skip to content

Commit ee34ac1

Browse files
committed
Let's have some sanity. Introduce a helper to issue a symbol table
warning.
1 parent 58177b9 commit ee34ac1

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

Python/compile.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3983,6 +3983,22 @@ get_ref_type(struct compiling *c, char *name)
39833983
return -1; /* can't get here */
39843984
}
39853985

3986+
/* Helper function to issue symbol table warnings */
3987+
3988+
static void
3989+
symtable_warn(struct symtable *st, char *msg)
3990+
{
3991+
if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
3992+
st->st_cur->ste_lineno, NULL, NULL) < 0) {
3993+
if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
3994+
PyErr_SetString(PyExc_SyntaxError, msg);
3995+
PyErr_SyntaxLocation(st->st_filename,
3996+
st->st_cur->ste_lineno);
3997+
}
3998+
st->st_errors++;
3999+
}
4000+
}
4001+
39864002
/* Helper function for setting lineno and filename */
39874003

39884004
static int
@@ -4837,22 +4853,7 @@ symtable_global(struct symtable *st, node *n)
48374853
name);
48384854
else
48394855
sprintf(buf, GLOBAL_AFTER_USE, name);
4840-
if (PyErr_WarnExplicit(PyExc_SyntaxWarning,
4841-
buf, st->st_filename,
4842-
st->st_cur->ste_lineno,
4843-
NULL, NULL) < 0)
4844-
{
4845-
if (PyErr_ExceptionMatches(
4846-
PyExc_SyntaxWarning))
4847-
{
4848-
PyErr_SetString(
4849-
PyExc_SyntaxError, buf);
4850-
PyErr_SyntaxLocation(
4851-
st->st_filename,
4852-
st->st_cur->ste_lineno);
4853-
}
4854-
st->st_errors++;
4855-
}
4856+
symtable_warn(st, buf);
48564857
}
48574858
}
48584859
symtable_add_def(st, name, DEF_GLOBAL);

0 commit comments

Comments
 (0)