Skip to content

Missing exception warnings #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_py3kwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)))
Expand Down
8 changes: 8 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down