Skip to content

Commit 48f8eb8

Browse files
Merge #14
14: Warn for raise with three compnents r=ltratt a=nanjekyejoannah This makes sense at the AST hence isolated from the [other exception PR](#12) Co-authored-by: Joannah Nanjekye <jnanjekye@python.org>
2 parents 4b248a8 + 99183ef commit 48f8eb8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Lib/test/test_py3kwarn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ def test_nonascii_bytes_literals(self):
369369
with check_py3k_warnings((expected, SyntaxWarning)):
370370
exec "b'\xbd'"
371371

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

373380
class TestStdlibRemovals(unittest.TestCase):
374381

Python/ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,12 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
24592459
else if (NCH(ch) == 6) {
24602460
expr_ty expr1, expr2, expr3;
24612461

2462+
if (Py_Py3kWarningFlag &&
2463+
!ast_3x_warn(c, n, "the raise clause with three components is not supported in 3.x",
2464+
"use 'raise' with a single object")) {
2465+
return NULL;
2466+
}
2467+
24622468
expr1 = ast_for_expr(c, CHILD(ch, 1));
24632469
if (!expr1)
24642470
return NULL;

0 commit comments

Comments
 (0)