Skip to content

Commit 070f0ab

Browse files
committed
Issue python#9125: Update parser module for "except ... as ..." syntax.
1 parent 2037913 commit 070f0ab

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Lib/test/test_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ def test_try_stmt(self):
235235
self.check_suite("try: pass\nexcept: pass\nelse: pass\n"
236236
"finally: pass\n")
237237

238+
def test_except_clause(self):
239+
self.check_suite("try: pass\nexcept: pass\n")
240+
self.check_suite("try: pass\nexcept A: pass\n")
241+
self.check_suite("try: pass\nexcept A, e: pass\n")
242+
self.check_suite("try: pass\nexcept A as e: pass\n")
243+
238244
def test_position(self):
239245
# An absolutely minimal test of position information. Better
240246
# tests would be a big project.

Misc/NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Library
2020
- Issue #9075: In the ssl module, remove the setting of a ``debug`` flag
2121
on an OpenSSL structure.
2222

23+
- Issue #9125: Add recognition of 'except ... as ...' syntax to parser module.
2324

2425
What's New in Python 2.7 release candidate 2?
2526
=============================================

Modules/parsermodule.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,10 +2126,13 @@ validate_except_clause(node *tree)
21262126

21272127
if (res && (nch > 1))
21282128
res = validate_test(CHILD(tree, 1));
2129-
if (res && (nch == 4))
2130-
res = (validate_comma(CHILD(tree, 2))
2131-
&& validate_test(CHILD(tree, 3)));
2132-
2129+
if (res && (nch == 4)) {
2130+
if (TYPE(CHILD(tree, 2)) == NAME)
2131+
res = validate_name(CHILD(tree, 2), "as");
2132+
else
2133+
res = validate_comma(CHILD(tree, 2));
2134+
res = res && validate_test(CHILD(tree, 3));
2135+
}
21332136
return (res);
21342137
}
21352138

0 commit comments

Comments
 (0)