Skip to content

Commit 20c571d

Browse files
missing exceptionwarnings
1 parent 8deb7c5 commit 20c571d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Lib/test/test_py3kwarn.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def test_backquote(self):
4545
with check_py3k_warnings((expected, SyntaxWarning)):
4646
exec "`2`" in {}
4747

48+
def test_except(self):
49+
expected = 'backquote not supported in 3.x; use repr()'
50+
with check_py3k_warnings((expected, SyntaxWarning)):
51+
exec "`2`" in {}
52+
4853
def test_paren_arg_names(self):
4954
expected = 'parenthesized argument names are invalid in 3.x'
5055
def check(s):
@@ -189,6 +194,11 @@ def test_sys_exc_clear(self):
189194
with check_py3k_warnings() as w:
190195
self.assertWarning(sys.exc_clear(), w, expected)
191196

197+
def test_sys_exc_info(self):
198+
expected = 'sys.exc_info() not supported in 3.x; use except clauses'
199+
with check_py3k_warnings() as w:
200+
self.assertWarning(sys.exc_info(), w, expected)
201+
192202
def test_methods_members(self):
193203
expected = '__members__ and __methods__ not supported in 3.x'
194204
class C:

Python/ast.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,11 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
24092409
n->n_col_offset, c->c_arena);
24102410
}
24112411
else if (NCH(ch) == 4) {
2412+
if (Py_Py3kWarningFlag &&
2413+
!ast_3x_warn(c, n, "the raise clause with three components is not supported in 3.x",
2414+
"use 'raise' with a single object")) {
2415+
return NULL;
2416+
}
24122417
expr_ty expr1, expr2;
24132418

24142419
expr1 = ast_for_expr(c, CHILD(ch, 1));
@@ -3059,6 +3064,20 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body)
30593064
asdl_seq *suite_seq;
30603065
expr_ty expression;
30613066
expr_ty e = ast_for_expr(c, CHILD(exc, 3));
3067+
expr_ty as_or_comma = ast_for_expr(c, CHILD(exc, 2));
3068+
3069+
if (TYPE(CHILD(exc, 2)) == COMMA)
3070+
if (Py_Py3kWarningFlag &&
3071+
!ast_3x_warn(c, exc, "the commas syntax for the except clause is not supported in 3.x",
3072+
"use the 'as' syntax instead")) {
3073+
return NULL;
3074+
}
3075+
if (e == Tuple_kind)
3076+
if (Py_Py3kWarningFlag &&
3077+
!ast_3x_warn(c, exc, "Iterable exceptions are not supported in 3.x",
3078+
"access the arguments through the 'args' attribute instead")) {
3079+
return NULL;
3080+
}
30623081
if (!e)
30633082
return NULL;
30643083
if (!set_context(c, e, Store, CHILD(exc, 3)))

Python/sysmodule.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ PyDoc_STRVAR(excepthook_doc,
149149
static PyObject *
150150
sys_exc_info(PyObject *self, PyObject *noargs)
151151
{
152+
if (Py_Py3kWarningFlag) {
153+
if (PyErr_WarnExplicit_WithFix(PyExc_Py3xWarning,
154+
"sys.exc_info() not supported in 3.x",
155+
"use except clauses", NULL, NULL,
156+
NULL, NULL)) {
157+
return NULL;
158+
}
159+
}
152160
PyThreadState *tstate;
153161
tstate = PyThreadState_GET();
154162
return Py_BuildValue(

0 commit comments

Comments
 (0)