diff --git a/hy/compiler.py b/hy/compiler.py index 35ac1f8..1b7988c 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -129,7 +129,7 @@ class HyASTCompiler(object): self.anon_fn_count = 0 self.imports = defaultdict(list) - def being_returnable(self, v): + def is_returnable(self, v): return temporary_attribute_value(self, "returnable", v) def compile(self, tree): @@ -954,7 +954,7 @@ class HyASTCompiler(object): @builds("foreach") @checkargs(min=1) def compile_for_expression(self, expression): - with self.being_returnable(False): + with self.is_returnable(False): expression.pop(0) # for name, iterable = expression.pop(0) target = self._storeize(self.compile_symbol(name)) @@ -1019,14 +1019,14 @@ class HyASTCompiler(object): body = [] if expression != []: - with self.being_returnable(True): + with self.is_returnable(True): tailop = self.compile(expression.pop(-1)) - with self.being_returnable(False): + with self.is_returnable(False): for el in expression: body.append(self.compile(el)) body.append(tailop) - with self.being_returnable(True): + with self.is_returnable(True): body = self._code_branch(body, expression.start_line, expression.start_column) diff --git a/hy/util.py b/hy/util.py index 6b26543..b855038 100644 --- a/hy/util.py +++ b/hy/util.py @@ -34,7 +34,12 @@ def temporary_attribute_value(obj, attribute, value): """Temporarily switch an object attribute value to another value.""" original_value = getattr(obj, attribute) setattr(obj, attribute, value) - yield + + try: + yield + except Exception: + pass + setattr(obj, attribute, original_value)