summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/transformer.py
diff options
context:
space:
mode:
authorPhillip J. Eby <pje@telecommunity.com>2005-08-02 00:46:46 (GMT)
committerPhillip J. Eby <pje@telecommunity.com>2005-08-02 00:46:46 (GMT)
commit0d6615fd29063bdaccb13e1fbae542fb666d8728 (patch)
tree0f18d41e2cb8831c9d244ab6586f9f8377592c67 /Lib/compiler/transformer.py
parentd794666048510deca0d4987a4c74d0fca85be411 (diff)
downloadcpython-0d6615fd29063bdaccb13e1fbae542fb666d8728.zip
cpython-0d6615fd29063bdaccb13e1fbae542fb666d8728.tar.gz
cpython-0d6615fd29063bdaccb13e1fbae542fb666d8728.tar.bz2
PEP 342 implementation. Per Guido's comments, the generator throw()
method still needs to support string exceptions, and allow None for the third argument. Documentation updates are needed, too.
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r--Lib/compiler/transformer.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 5844bb5..4759280 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -403,7 +403,15 @@ class Transformer:
return Return(self.com_node(nodelist[1]), lineno=nodelist[0][2])
def yield_stmt(self, nodelist):
- return Yield(self.com_node(nodelist[1]), lineno=nodelist[0][2])
+ expr = self.com_node(nodelist[0])
+ return Discard(expr, lineno=expr.lineno)
+
+ def yield_expr(self, nodelist):
+ if len(nodelist)>1:
+ value = nodelist[1]
+ else:
+ value = Const(None)
+ return Yield(self.com_node(value), lineno=nodelist[0][2])
def raise_stmt(self, nodelist):
# raise: [test [',' test [',' test]]]
@@ -1402,6 +1410,8 @@ _legal_node_types = [
if hasattr(symbol, 'yield_stmt'):
_legal_node_types.append(symbol.yield_stmt)
+if hasattr(symbol, 'yield_expr'):
+ _legal_node_types.append(symbol.yield_expr)
_assign_types = [
symbol.test,