Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins
cpython (3.2): Issue #14701: Add missing support for 'raise ... from' in parser module.
 

Index | Next | Previous | View Flat


python-checkins at python

May 7, 2012, 4:03 AM


Views: 66
Permalink
cpython (3.2): Issue #14701: Add missing support for 'raise ... from' in parser module.

http://hg.python.org/cpython/rev/fc17f70292f6
changeset: 76818:fc17f70292f6
branch: 3.2
parent: 76812:84a4bbcbed1d
user: Mark Dickinson <mdickinson [at] enthought>
date: Mon May 07 12:01:27 2012 +0100
summary:
Issue #14701: Add missing support for 'raise ... from' in parser module.

files:
Lib/test/test_parser.py | 8 ++++++++
Misc/NEWS | 2 ++
Modules/parsermodule.c | 23 +++++++++++------------
3 files changed, 21 insertions(+), 12 deletions(-)


diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -297,6 +297,14 @@
self.check_suite("[*a, *b] = y")
self.check_suite("for [*x, b] in x: pass")

+ def test_raise_statement(self):
+ self.check_suite("raise\n")
+ self.check_suite("raise e\n")
+ self.check_suite("try:\n"
+ " suite\n"
+ "except Exception as e:\n"
+ " raise ValueError from e\n")
+

#
# Second, we take *invalid* trees and make sure we get ParserError
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -61,6 +61,8 @@
Library
-------

+- Issue #14701: Fix missing support for 'raise ... from' in parser module.
+
- Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running
step. Patch by Xavier de Gaye.

diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1608,31 +1608,30 @@
}


+/*
+ * raise_stmt:
+ *
+ * 'raise' [test ['from' test]]
+ */
static int
validate_raise_stmt(node *tree)
{
int nch = NCH(tree);
int res = (validate_ntype(tree, raise_stmt)
- && ((nch == 1) || (nch == 2) || (nch == 4) || (nch == 6)));
+ && ((nch == 1) || (nch == 2) || (nch == 4)));
+
+ if (!res && !PyErr_Occurred())
+ (void) validate_numnodes(tree, 2, "raise");

if (res) {
res = validate_name(CHILD(tree, 0), "raise");
if (res && (nch >= 2))
res = validate_test(CHILD(tree, 1));
- if (res && nch > 2) {
- res = (validate_comma(CHILD(tree, 2))
+ if (res && (nch == 4)) {
+ res = (validate_name(CHILD(tree, 2), "from")
&& validate_test(CHILD(tree, 3)));
- if (res && (nch > 4))
- res = (validate_comma(CHILD(tree, 4))
- && validate_test(CHILD(tree, 5)));
}
}
- else
- (void) validate_numnodes(tree, 2, "raise");
- if (res && (nch == 4))
- res = (validate_comma(CHILD(tree, 2))
- && validate_test(CHILD(tree, 3)));
-
return (res);
}


--
Repository URL: http://hg.python.org/cpython

Subject User Time
cpython (3.2): Issue #14701: Add missing support for 'raise ... from' in parser module. python-checkins at python May 7, 2012, 4:03 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.