Skip to content

Commit

Permalink
Merge python#14
Browse files Browse the repository at this point in the history
14: Warn for raise with three compnents r=ltratt a=nanjekyejoannah

This makes sense at the AST hence isolated from the [other exception PR](softdevteam#12)

Co-authored-by: Joannah Nanjekye <jnanjekye@python.org>
  • Loading branch information
bors[bot] and nanjekyejoannah authored Nov 25, 2022
2 parents 4b248a8 + 99183ef commit 48f8eb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 48f8eb8

Please sign in to comment.