From ccd26205d76f4c99347f2eee5a9b7bf1147ce935 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Sun, 24 Mar 2013 10:00:07 -0400 Subject: [PATCH] unbreak py3.3? need to re-add with --- hy/compiler.py | 28 ++++++++++------------------ tests/native_tests/language.hy | 2 -- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index 4756ad7..c2a4469 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -309,16 +309,6 @@ class HyASTCompiler(object): fn.decorator_list = [self.compile(x) for x in expr] return fn - @builds("with") - def compile_with_expression(self, expr): - expr.pop(0) # with - return ast.With(context_expr=self.compile(expr.pop(0)), - lineno=expr.start_line, - col_offset=expr.start_column, - optional_vars=None, - body=self._mangle_branch([ - self.compile(x) for x in expr])) - @builds("with_as") def compile_with_as_expression(self, expr): expr.pop(0) # with-as @@ -326,15 +316,17 @@ class HyASTCompiler(object): thing = self.compile(expr.pop(0)) thing.ctx = ast.Store() - # Module(body=[With(items=[withitem(context_expr=Name(id='foo', ctx=Load()), optional_vars=Name(id='e', ctx=Store()))], body=[Pass()])]) - # Module(body=[With(context_expr=Name(id='foo', ctx=Load()), optional_vars=Name(id='e', ctx=Store()), body=[Pass()])]) + ret = ast.With(context_expr=ctx, + lineno=expr.start_line, + col_offset=expr.start_column, + optional_vars=thing, + body=self._mangle_branch([ + self.compile(x) for x in expr])) - return ast.With(context_expr=ctx, - lineno=expr.start_line, - col_offset=expr.start_column, - optional_vars=thing, - body=self._mangle_branch([ - self.compile(x) for x in expr])) + if sys.version_info[0] >= 3 and sys.version_info[1] >= 3: + ret.items = [ast.withitem(context_expr=ctx, optional_vars=thing)] + + return ret @builds("kwapply") def compile_kwapply_expression(self, expr): diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 915a4ff..f8cd50a 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -198,7 +198,5 @@ (defn test-context [] "NATIVE: test with" - (with (open "README.md" "r") - (pass)) (with-as (open "README.md" "r") fd (pass)))