summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/transformer.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r--Lib/compiler/transformer.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index ae9b819..eed9ce9 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -536,6 +536,12 @@ class Transformer:
return self.com_try_except(nodelist)
+ def with_stmt(self, nodelist):
+ return self.com_with(nodelist)
+
+ def with_var(self, nodelist):
+ return self.com_with_var(nodelist)
+
def suite(self, nodelist):
# simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
if len(nodelist) == 1:
@@ -926,6 +932,20 @@ class Transformer:
return TryExcept(self.com_node(nodelist[2]), clauses, elseNode,
lineno=nodelist[0][2])
+ def com_with(self, nodelist):
+ # with_stmt: 'with' expr [with_var] ':' suite
+ expr = self.com_node(nodelist[1])
+ body = self.com_node(nodelist[-1])
+ if nodelist[2][0] == token.COLON:
+ var = None
+ else:
+ var = self.com_node(nodelist[2])
+ return With(expr, var, body, lineno=nodelist[0][2])
+
+ 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]
@@ -1390,6 +1410,7 @@ _legal_node_types = [
symbol.while_stmt,
symbol.for_stmt,
symbol.try_stmt,
+ symbol.with_stmt,
symbol.suite,
symbol.testlist,
symbol.testlist_safe,