[Python-checkins] r55446 - in python/trunk: Grammar/Grammar Lib/compiler/transformer.py Lib/test/test_grammar.py Misc/NEWS Python/ast.c Python/graminit.c

collin.winter python-checkins at python.org
Sat May 19 01:11:27 CEST 2007


Author: collin.winter
Date: Sat May 19 01:11:24 2007
New Revision: 55446

Modified:
   python/trunk/Grammar/Grammar
   python/trunk/Lib/compiler/transformer.py
   python/trunk/Lib/test/test_grammar.py
   python/trunk/Misc/NEWS
   python/trunk/Python/ast.c
   python/trunk/Python/graminit.c
Log:
Backport PEP 3110's new 'except' syntax to 2.6.

Modified: python/trunk/Grammar/Grammar
==============================================================================
--- python/trunk/Grammar/Grammar	(original)
+++ python/trunk/Grammar/Grammar	Sat May 19 01:11:24 2007
@@ -85,7 +85,7 @@
 with_stmt: 'with' test [ with_var ] ':' suite
 with_var: 'as' expr
 # NB compile.c makes sure that the default except clause is last
-except_clause: 'except' [test [',' test]]
+except_clause: 'except' [test [('as' | ',') test]]
 suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
 
 # Backward compatibility cruft to support:

Modified: python/trunk/Lib/compiler/transformer.py
==============================================================================
--- python/trunk/Lib/compiler/transformer.py	(original)
+++ python/trunk/Lib/compiler/transformer.py	Sat May 19 01:11:24 2007
@@ -930,7 +930,7 @@
         for i in range(3, len(nodelist), 3):
             node = nodelist[i]
             if node[0] == symbol.except_clause:
-                # except_clause: 'except' [expr [',' expr]] */
+                # except_clause: 'except' [expr [(',' | 'as') expr]] */
                 if len(node) > 2:
                     expr1 = self.com_node(node[2])
                     if len(node) > 4:

Modified: python/trunk/Lib/test/test_grammar.py
==============================================================================
--- python/trunk/Lib/test/test_grammar.py	(original)
+++ python/trunk/Lib/test/test_grammar.py	Sat May 19 01:11:24 2007
@@ -600,7 +600,7 @@
     def testTry(self):
         ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
         ###         | 'try' ':' suite 'finally' ':' suite
-        ### except_clause: 'except' [expr [',' expr]]
+        ### except_clause: 'except' [expr [('as' | ',') expr]]
         try:
             1/0
         except ZeroDivisionError:
@@ -609,7 +609,7 @@
             pass
         try: 1/0
         except EOFError: pass
-        except TypeError, msg: pass
+        except TypeError as msg: pass
         except RuntimeError, msg: pass
         except: pass
         else: pass

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat May 19 01:11:24 2007
@@ -12,6 +12,10 @@
 Core and builtins
 -----------------
 
+- except clauses may now be spelled either "except E, target:" or
+  "except E as target:". This is to provide forwards compatibility with
+  Python 3.0.
+
 - Deprecate BaseException.message as per PEP 352.
 
 - Bug #1303614: don't expose object's __dict__ when the dict is

Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Sat May 19 01:11:24 2007
@@ -2765,7 +2765,7 @@
 static excepthandler_ty
 ast_for_except_clause(struct compiling *c, const node *exc, node *body)
 {
-    /* except_clause: 'except' [test [',' test]] */
+    /* except_clause: 'except' [test [(',' | 'as') test]] */
     REQ(exc, except_clause);
     REQ(body, suite);
 

Modified: python/trunk/Python/graminit.c
==============================================================================
--- python/trunk/Python/graminit.c	(original)
+++ python/trunk/Python/graminit.c	Sat May 19 01:11:24 2007
@@ -931,7 +931,8 @@
 	{26, 2},
 	{0, 1},
 };
-static arc arcs_42_2[2] = {
+static arc arcs_42_2[3] = {
+	{78, 3},
 	{27, 3},
 	{0, 2},
 };
@@ -944,7 +945,7 @@
 static state states_42[5] = {
 	{1, arcs_42_0},
 	{2, arcs_42_1},
-	{2, arcs_42_2},
+	{3, arcs_42_2},
 	{1, arcs_42_3},
 	{1, arcs_42_4},
 };


More information about the Python-checkins mailing list