diff --git a/Lib/test/test_py3kwarn.py b/Lib/test/test_py3kwarn.py index 8d1163ea0004b8..2c1d6fb3aebf39 100644 --- a/Lib/test/test_py3kwarn.py +++ b/Lib/test/test_py3kwarn.py @@ -189,6 +189,11 @@ def test_sys_exc_clear(self): with check_py3k_warnings() as w: self.assertWarning(sys.exc_clear(), w, expected) + def test_sys_exc_info(self): + expected = 'sys.exc_info() not supported in 3.x; use except clauses' + with check_py3k_warnings() as w: + self.assertWarning(sys.exc_info(), w, expected) + def test_methods_members(self): expected = '__members__ and __methods__ not supported in 3.x' class C: diff --git a/Python/ast.c b/Python/ast.c index 54692364b0f554..48ad808e394070 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2409,6 +2409,11 @@ ast_for_flow_stmt(struct compiling *c, const node *n) n->n_col_offset, c->c_arena); } else if (NCH(ch) == 4) { + if (Py_Py3kWarningFlag && + !ast_3x_warn(c, n, "the raise clause with three components is not supported in 3.x", + "use 'raise' with a single object")) { + return NULL; + } expr_ty expr1, expr2; expr1 = ast_for_expr(c, CHILD(ch, 1)); @@ -3059,6 +3064,20 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body) asdl_seq *suite_seq; expr_ty expression; expr_ty e = ast_for_expr(c, CHILD(exc, 3)); + expr_ty as_or_comma = ast_for_expr(c, CHILD(exc, 2)); + + if (TYPE(CHILD(exc, 2)) == COMMA) + if (Py_Py3kWarningFlag && + !ast_3x_warn(c, exc, "the commas syntax for the except clause is not supported in 3.x", + "use the 'as' syntax instead")) { + return NULL; + } + if (e == Tuple_kind) + if (Py_Py3kWarningFlag && + !ast_3x_warn(c, exc, "Iterable exceptions are not supported in 3.x", + "access the arguments through the 'args' attribute instead")) { + return NULL; + } if (!e) return NULL; if (!set_context(c, e, Store, CHILD(exc, 3))) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index fdb7af2f5f6764..ccaefd91326742 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -149,6 +149,14 @@ PyDoc_STRVAR(excepthook_doc, static PyObject * sys_exc_info(PyObject *self, PyObject *noargs) { + if (Py_Py3kWarningFlag) { + if (PyErr_WarnExplicit_WithFix(PyExc_Py3xWarning, + "sys.exc_info() not supported in 3.x", + "use except clauses", NULL, NULL, + NULL, NULL)) { + return NULL; + } + } PyThreadState *tstate; tstate = PyThreadState_GET(); return Py_BuildValue(