From 2ef9bc75d4b52a351f8662f5e8e6b607245e87d2 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Thu, 3 Aug 2017 17:38:26 -0700 Subject: [PATCH] Clean up `with` --- hy/compiler.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index 2143fd4..8b3e1c2 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -1452,25 +1452,22 @@ class HyASTCompiler(object): raise HyTypeError(expr, "with expects a list, received `{0}'".format( type(args).__name__)) - if len(args) < 1: - raise HyTypeError(expr, "with needs [[arg (expr)]] or [[(expr)]]]") - - args.reverse() - ctx = self.compile(args.pop(0)) + if len(args) not in (1, 2): + raise HyTypeError(expr, "with needs [arg (expr)] or [(expr)]") thing = None - if args != []: + if len(args) == 2: thing = self._storeize(args[0], self.compile(args.pop(0))) + ctx = self.compile(args.pop(0)) body = self._compile_branch(expr) + # Store the result of the body in a tempvar var = self.get_anon_var() name = ast.Name(id=ast_str(var), arg=ast_str(var), ctx=ast.Store(), lineno=expr.start_line, col_offset=expr.start_column) - - # Store the result of the body in a tempvar body += ast.Assign(targets=[name], value=body.force_expr, lineno=expr.start_line,