summaryrefslogtreecommitdiffstats
path: root/Lib/compiler
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-02-27 22:32:47 (GMT)
committerGuido van Rossum <guido@python.org>2006-02-27 22:32:47 (GMT)
commitc2e20744b2b7811632030470971c31630f0975e2 (patch)
treee97b1c1471fd00e4e5648ed317274c1d9005d2ca /Lib/compiler
parent5fec904f84a40005f824abe295525a1710056be0 (diff)
downloadcpython-c2e20744b2b7811632030470971c31630f0975e2.zip
cpython-c2e20744b2b7811632030470971c31630f0975e2.tar.gz
cpython-c2e20744b2b7811632030470971c31630f0975e2.tar.bz2
PEP 343 -- the with-statement.
This was started by Mike Bland and completed by Guido (with help from Neal). This still needs a __future__ statement added; Thomas is working on Michael's patch for that aspect. There's a small amount of code cleanup and refactoring in ast.c, compile.c and ceval.c (I fixed the lltrace behavior when EXT_POP is used -- however I had to make lltrace a static global).
Diffstat (limited to 'Lib/compiler')
-rw-r--r--Lib/compiler/ast.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py
index accda45..e270995 100644
--- a/Lib/compiler/ast.py
+++ b/Lib/compiler/ast.py
@@ -553,7 +553,7 @@ class Function(Node):
self.varargs = 1
if flags & CO_VARKEYWORDS:
self.kwargs = 1
-
+
def getChildren(self):
@@ -584,7 +584,7 @@ class GenExpr(Node):
self.lineno = lineno
self.argnames = ['[outmost-iterable]']
self.varargs = self.kwargs = None
-
+
def getChildren(self):
@@ -763,7 +763,7 @@ class Lambda(Node):
self.varargs = 1
if flags & CO_VARKEYWORDS:
self.kwargs = 1
-
+
def getChildren(self):
@@ -1297,6 +1297,31 @@ class While(Node):
def __repr__(self):
return "While(%s, %s, %s)" % (repr(self.test), repr(self.body), repr(self.else_))
+class With(Node):
+ def __init__(self, expr, vars, body, lineno=None):
+ self.expr = expr
+ self.vars = vars
+ self.body = body
+ self.lineno = lineno
+
+ def getChildren(self):
+ children = []
+ children.append(self.expr)
+ children.append(self.vars)
+ children.append(self.body)
+ return tuple(children)
+
+ def getChildNodes(self):
+ nodelist = []
+ nodelist.append(self.expr)
+ if self.vars is not None:
+ nodelist.append(self.vars)
+ nodelist.append(self.body)
+ return tuple(nodelist)
+
+ def __repr__(self):
+ return "With(%s, %s, %s)" % (repr(self.expr), repr(self.vars), repr(self.body))
+
class Yield(Node):
def __init__(self, value, lineno=None):
self.value = value