]> granicus.if.org Git - python/commitdiff
Backport PEP 3110's new 'except' syntax to 2.6.
authorCollin Winter <collinw@gmail.com>
Fri, 18 May 2007 23:11:24 +0000 (23:11 +0000)
committerCollin Winter <collinw@gmail.com>
Fri, 18 May 2007 23:11:24 +0000 (23:11 +0000)
Grammar/Grammar
Lib/compiler/transformer.py
Lib/test/test_grammar.py
Misc/NEWS
Python/ast.c
Python/graminit.c

index 83e50582fbc0e305a18f790edc62f22e1d6c698f..cdfce69ac564950d6850a4c5fc08b62d5fb42361 100644 (file)
@@ -85,7 +85,7 @@ try_stmt: ('try' ':' suite
 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:
index ac23ad18a99156b07bf74a318847a962f97336a0..77ac7764bf07dfec9eb51f627c1bf092201ef5f8 100644 (file)
@@ -930,7 +930,7 @@ class Transformer:
         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:
index 14ce7e49a81239ce62059b6aaed26ca87e11d11e..51d77f2ef5e85d4ad4a2c0ce3d8951542fc08952 100644 (file)
@@ -600,7 +600,7 @@ hello world
     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 @@ hello world
             pass
         try: 1/0
         except EOFError: pass
-        except TypeError, msg: pass
+        except TypeError as msg: pass
         except RuntimeError, msg: pass
         except: pass
         else: pass
index fabd5f436db5d70ec6578ab54a0afe125a3c5dd0..83f3da18abd04bb43e7adabac5150258fdc37bd3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.6 alpha 1?
 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
index ace4950402e944c4ed5cbaaedf425b0bc38921fa..27c3efaac87327a61e56722b8ed89d796443baa2 100644 (file)
@@ -2765,7 +2765,7 @@ ast_for_for_stmt(struct compiling *c, const node *n)
 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);
 
index 33ef64b8b7f7a4f8ba018c70771216edc83bc78e..1f7450423537f9ed7b2930a1627113f98fdf7d13 100644 (file)
@@ -931,7 +931,8 @@ static arc arcs_42_1[2] = {
        {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 arc arcs_42_4[1] = {
 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},
 };