[Python-checkins] r47057 - in python/trunk: Lib/compiler/transformer.py Misc/NEWS
Neal Norwitz
nnorwitz at gmail.com
Wed Jun 21 19:53:43 CEST 2006
Can we get a test for this?
On 6/21/06, georg.brandl <python-checkins at python.org> wrote:
> Author: georg.brandl
> Date: Wed Jun 21 19:45:17 2006
> New Revision: 47057
>
> Modified:
> python/trunk/Lib/compiler/transformer.py
> python/trunk/Misc/NEWS
> Log:
> fix [ 1509132 ] compiler module builds incorrect AST for TryExceptFinally
>
>
>
> Modified: python/trunk/Lib/compiler/transformer.py
> ==============================================================================
> --- python/trunk/Lib/compiler/transformer.py (original)
> +++ python/trunk/Lib/compiler/transformer.py Wed Jun 21 19:45:17 2006
> @@ -536,12 +536,7 @@
> lineno=nodelist[0][2])
>
> def try_stmt(self, nodelist):
> - # 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
> - # | 'try' ':' suite 'finally' ':' suite
> - if nodelist[3][0] != symbol.except_clause:
> - return self.com_try_finally(nodelist)
> -
> - return self.com_try_except(nodelist)
> + return self.com_try_except_finally(nodelist)
>
> def with_stmt(self, nodelist):
> return self.com_with(nodelist)
> @@ -917,18 +912,21 @@
> bases.append(self.com_node(node[i]))
> return bases
>
> - def com_try_finally(self, nodelist):
> - # try_fin_stmt: "try" ":" suite "finally" ":" suite
> - return TryFinally(self.com_node(nodelist[2]),
> - self.com_node(nodelist[5]),
> - lineno=nodelist[0][2])
> -
> - def com_try_except(self, nodelist):
> - # try_except: 'try' ':' suite (except_clause ':' suite)* ['else' suite]
> + def com_try_except_finally(self, nodelist):
> + # ('try' ':' suite
> + # ((except_clause ':' suite)+ ['else' ':' suite] ['finally' ':' suite]
> + # | 'finally' ':' suite))
> +
> + if nodelist[3][0] == token.NAME:
> + # first clause is a finally clause: only try-finally
> + return TryFinally(self.com_node(nodelist[2]),
> + self.com_node(nodelist[5]),
> + lineno=nodelist[0][2])
> +
> #tryexcept: [TryNode, [except_clauses], elseNode)]
> - stmt = self.com_node(nodelist[2])
> clauses = []
> elseNode = None
> + finallyNode = None
> for i in range(3, len(nodelist), 3):
> node = nodelist[i]
> if node[0] == symbol.except_clause:
> @@ -944,9 +942,16 @@
> clauses.append((expr1, expr2, self.com_node(nodelist[i+2])))
>
> if node[0] == token.NAME:
> - elseNode = self.com_node(nodelist[i+2])
> - return TryExcept(self.com_node(nodelist[2]), clauses, elseNode,
> - lineno=nodelist[0][2])
> + if node[1] == 'else':
> + elseNode = self.com_node(nodelist[i+2])
> + elif node[1] == 'finally':
> + finallyNode = self.com_node(nodelist[i+2])
> + try_except = TryExcept(self.com_node(nodelist[2]), clauses, elseNode,
> + lineno=nodelist[0][2])
> + if finallyNode:
> + return TryFinally(try_except, finallyNode, lineno=nodelist[0][2])
> + else:
> + return try_except
>
> def com_with(self, nodelist):
> # with_stmt: 'with' expr [with_var] ':' suite
>
> Modified: python/trunk/Misc/NEWS
> ==============================================================================
> --- python/trunk/Misc/NEWS (original)
> +++ python/trunk/Misc/NEWS Wed Jun 21 19:45:17 2006
> @@ -4,8 +4,25 @@
>
> (editors: check NEWS.help for information about editing NEWS using ReST.)
>
> +What's New in Python 2.5 beta 2?
> +================================
> +
> +*Release date: XX-JUL-2006*
> +
> +Core and builtins
> +-----------------
> +
> +
> +Library
> +-------
> +
> +- The compiler module now correctly compiles the new try-except-finally
> + statement (bug #1509132).
> +
> +
> +
> What's New in Python 2.5 beta 1?
> -=================================
> +================================
>
> *Release date: 20-JUN-2006*
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
More information about the Python-checkins
mailing list