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

Skip to content

Commit 207fda6

Browse files
committed
Refactored the warning-issuing code more.
Made sure that the warnings issued by symtable_check_unoptimized() (about import * and exec) contain the proper filename and line number, and are transformed into SyntaxError exceptions with -Werror.
1 parent 677898a commit 207fda6

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

Python/compile.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,18 +4015,26 @@ get_ref_type(struct compiling *c, char *name)
40154015
return -1; /* can't get here */
40164016
}
40174017

4018-
/* Helper function to issue symbol table warnings */
4018+
/* Helper functions to issue warnings */
40194019

40204020
static int
4021-
symtable_warn(struct symtable *st, char *msg)
4021+
issue_warning(char *msg, char *filename, int lineno)
40224022
{
4023-
if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
4024-
st->st_cur->ste_lineno, NULL, NULL) < 0) {
4023+
if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, filename,
4024+
lineno, NULL, NULL) < 0) {
40254025
if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
40264026
PyErr_SetString(PyExc_SyntaxError, msg);
4027-
PyErr_SyntaxLocation(st->st_filename,
4028-
st->st_cur->ste_lineno);
4027+
PyErr_SyntaxLocation(filename, lineno);
40294028
}
4029+
return -1;
4030+
}
4031+
return 0;
4032+
}
4033+
4034+
static int
4035+
symtable_warn(struct symtable *st, char *msg)
4036+
{
4037+
if (issue_warning(msg, st->st_filename, st->st_cur->ste_lineno) < 0) {
40304038
st->st_errors++;
40314039
return -1;
40324040
}
@@ -4195,11 +4203,9 @@ symtable_check_unoptimized(struct compiling *c,
41954203
PyErr_SyntaxLocation(c->c_symtable->st_filename,
41964204
ste->ste_lineno);
41974205
return -1;
4198-
} else {
4199-
/* XXX if the warning becomes an exception, we should
4200-
attached more info to it. */
4201-
if (PyErr_Warn(PyExc_SyntaxWarning, buf) < 0)
4202-
return -1;
4206+
}
4207+
else {
4208+
return issue_warning(buf, c->c_filename, ste->ste_lineno);
42034209
}
42044210
return 0;
42054211
}

0 commit comments

Comments
 (0)