mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Use the new PyErr_WarnExplicit() API to issue better warnings for
global after assign / use. Note: I'm not updating the PyErr_Warn() call for import * / exec combined with a function, because I can't trigger it with an example. Jeremy, just follow the example of the call to PyErr_WarnExplicit() that I *did* include.
This commit is contained in:
parent
9da7f3b4f4
commit
0bba7f83f2
1 changed files with 21 additions and 12 deletions
|
@ -4830,18 +4830,27 @@ symtable_global(struct symtable *st, node *n)
|
||||||
st->st_cur->ste_lineno);
|
st->st_cur->ste_lineno);
|
||||||
st->st_errors++;
|
st->st_errors++;
|
||||||
return;
|
return;
|
||||||
} else if (flags & DEF_LOCAL) {
|
|
||||||
sprintf(buf, GLOBAL_AFTER_ASSIGN, name);
|
|
||||||
if (PyErr_Warn(PyExc_SyntaxWarning,
|
|
||||||
buf) < 0) {
|
|
||||||
/* XXX set line number? */
|
|
||||||
st->st_errors++;
|
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
|
if (flags & DEF_LOCAL)
|
||||||
|
sprintf(buf, GLOBAL_AFTER_ASSIGN,
|
||||||
|
name);
|
||||||
|
else
|
||||||
sprintf(buf, GLOBAL_AFTER_USE, name);
|
sprintf(buf, GLOBAL_AFTER_USE, name);
|
||||||
if (PyErr_Warn(PyExc_SyntaxWarning,
|
if (PyErr_WarnExplicit(PyExc_SyntaxWarning,
|
||||||
buf) < 0) {
|
buf, st->st_filename,
|
||||||
/* XXX set line number? */
|
st->st_cur->ste_lineno,
|
||||||
|
NULL, NULL) < 0)
|
||||||
|
{
|
||||||
|
if (PyErr_ExceptionMatches(
|
||||||
|
PyExc_SyntaxWarning))
|
||||||
|
{
|
||||||
|
PyErr_SetString(
|
||||||
|
PyExc_SyntaxError, buf);
|
||||||
|
PyErr_SyntaxLocation(
|
||||||
|
st->st_filename,
|
||||||
|
st->st_cur->ste_lineno);
|
||||||
|
}
|
||||||
st->st_errors++;
|
st->st_errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue