summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-06-08 15:45:23 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-06-08 15:45:23 (GMT)
commitcbd78133fa68bd646bc0e77ea28cb73ed5a9c188 (patch)
tree8aa13a21515b97f549740180ce039da26db64a19 /Python
parent3219df1562570c544d42533df259128a507da809 (diff)
downloadcpython-cbd78133fa68bd646bc0e77ea28cb73ed5a9c188.zip
cpython-cbd78133fa68bd646bc0e77ea28cb73ed5a9c188.tar.gz
cpython-cbd78133fa68bd646bc0e77ea28cb73ed5a9c188.tar.bz2
add an ast_warn helper function to make adding those Py3k warnings easier
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 863906f..ad78840 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -113,6 +113,19 @@ ast_error_finish(const char *filename)
PyErr_Restore(type, value, tback);
}
+static int
+ast_warn(struct compiling *c, const node *n, char *msg)
+{
+ if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename, LINENO(n),
+ NULL, NULL) < 0) {
+ /* if -Werr, change it to a SyntaxError */
+ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SyntaxWarning))
+ ast_error(n, msg);
+ return 0;
+ }
+ return 1;
+}
+
/* num_stmts() returns number of contained statements.
Use this routine to determine how big a sequence is needed for
@@ -1363,14 +1376,9 @@ ast_for_atom(struct compiling *c, const node *n)
}
case BACKQUOTE: { /* repr */
expr_ty expression;
- if (Py_Py3kWarningFlag) {
- if (PyErr_WarnExplicit(PyExc_SyntaxWarning,
- "backquote not supported in 3.x; use repr()",
- c->c_filename, LINENO(n),
- NULL, NULL)) {
+ if (Py_Py3kWarningFlag &&
+ !ast_warn(c, n, "backquote not supported in 3.x; use repr()"))
return NULL;
- }
- }
expression = ast_for_testlist(c, CHILD(n, 1));
if (!expression)
return NULL;