diff options
author | Guido van Rossum <guido@python.org> | 2001-02-28 21:55:38 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-02-28 21:55:38 +0000 |
commit | 19bc6a1f231d40f9c5df2318780eb8f7118f81b8 (patch) | |
tree | 9f663aa6d3a068cf2aecd8116ed8f108b8404b3b /Python/compile.c | |
parent | 5bff11964d68171e7cf5d636922a254e66951349 (diff) | |
download | cpython-19bc6a1f231d40f9c5df2318780eb8f7118f81b8.tar.gz |
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.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/Python/compile.c b/Python/compile.c index b44512271b..6b5fa11705 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4830,18 +4830,27 @@ symtable_global(struct symtable *st, node *n) st->st_cur->ste_lineno); st->st_errors++; 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 { - sprintf(buf, GLOBAL_AFTER_USE, name); - if (PyErr_Warn(PyExc_SyntaxWarning, - buf) < 0) { - /* XXX set line number? */ + } + else { + if (flags & DEF_LOCAL) + sprintf(buf, GLOBAL_AFTER_ASSIGN, + name); + else + sprintf(buf, GLOBAL_AFTER_USE, name); + if (PyErr_WarnExplicit(PyExc_SyntaxWarning, + buf, st->st_filename, + 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++; } } |