Skip to content

Warn for raise with three compnents #14

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

Merged
merged 1 commit into from
Nov 25, 2022
Merged
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
7 changes: 7 additions & 0 deletions Lib/test/test_py3kwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ def test_nonascii_bytes_literals(self):
with check_py3k_warnings((expected, SyntaxWarning)):
exec "b'\xbd'"

def test_raise_three_components(self):
expected = """the raise clause with three components is not supported in 3.x; \
use 'raise' with a single object"""
with check_py3k_warnings((expected, SyntaxWarning)):
excType, excValue, excTraceback = sys.exc_info()
raise excType, excValue, excTraceback


class TestStdlibRemovals(unittest.TestCase):

Expand Down
6 changes: 6 additions & 0 deletions Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,12 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
else if (NCH(ch) == 6) {
expr_ty expr1, expr2, expr3;

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;
}

expr1 = ast_for_expr(c, CHILD(ch, 1));
if (!expr1)
return NULL;
Expand Down