Skip to content

Commit 12bed85

Browse files
author
benjamin.peterson
committed
add an ast_warn helper function to make adding those Py3k warnings easier
git-svn-id: http://svn.python.org/projects/python/trunk@64040 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent b629939 commit 12bed85

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

Python/ast.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ ast_error_finish(const char *filename)
113113
PyErr_Restore(type, value, tback);
114114
}
115115

116+
static int
117+
ast_warn(struct compiling *c, const node *n, char *msg)
118+
{
119+
if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, c->c_filename, LINENO(n),
120+
NULL, NULL) < 0) {
121+
/* if -Werr, change it to a SyntaxError */
122+
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SyntaxWarning))
123+
ast_error(n, msg);
124+
return 0;
125+
}
126+
return 1;
127+
}
128+
116129
/* num_stmts() returns number of contained statements.
117130
118131
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)
13631376
}
13641377
case BACKQUOTE: { /* repr */
13651378
expr_ty expression;
1366-
if (Py_Py3kWarningFlag) {
1367-
if (PyErr_WarnExplicit(PyExc_SyntaxWarning,
1368-
"backquote not supported in 3.x; use repr()",
1369-
c->c_filename, LINENO(n),
1370-
NULL, NULL)) {
1379+
if (Py_Py3kWarningFlag &&
1380+
!ast_warn(c, n, "backquote not supported in 3.x; use repr()"))
13711381
return NULL;
1372-
}
1373-
}
13741382
expression = ast_for_testlist(c, CHILD(n, 1));
13751383
if (!expression)
13761384
return NULL;

0 commit comments

Comments
 (0)