Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(985)

Unified Diff: Lib/compiler/transformer.py

Issue 53094: Multi with statement Base URL: http://svn.python.org/view/*checkout*/python/trunk/
Patch Set: Version after review by Benjamin Created 14 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Include/graminit.h ('k') | Lib/test/test_compiler.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/compiler/transformer.py
===================================================================
--- Lib/compiler/transformer.py (revision 72182)
+++ Lib/compiler/transformer.py (working copy)
@@ -965,19 +965,23 @@
return try_except
def com_with(self, nodelist):
- # with_stmt: 'with' expr [with_var] ':' suite
- expr = self.com_node(nodelist[1])
+ # with_stmt: 'with' with_item (',' with_item)* ':' suite
body = self.com_node(nodelist[-1])
- if nodelist[2][0] == token.COLON:
+ for i in range(len(nodelist) - 3, 0, -2):
+ ret = self.com_with_item(nodelist[i], body, nodelist[0][2])
+ if i == 1:
+ return ret
+ body = ret
+
+ def com_with_item(self, nodelist, body, lineno):
+ # with_item: test ['as' expr]
+ if len(nodelist) == 4:
+ var = self.com_assign(nodelist[3], OP_ASSIGN)
+ else:
var = None
- else:
- var = self.com_assign(nodelist[2][2], OP_ASSIGN)
- return With(expr, var, body, lineno=nodelist[0][2])
+ expr = self.com_node(nodelist[1])
+ return With(expr, var, body, lineno=lineno)
- def com_with_var(self, nodelist):
- # with_var: 'as' expr
- return self.com_node(nodelist[1])
-
def com_augassign_op(self, node):
assert node[0] == symbol.augassign
return node[1]
« no previous file with comments | « Include/graminit.h ('k') | Lib/test/test_compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b