diff --git a/hy/__init__.py b/hy/__init__.py index bd4d8a9..f86ddec 100644 --- a/hy/__init__.py +++ b/hy/__init__.py @@ -23,4 +23,5 @@ __appname__ = "hy" __version__ = "0.ALPHA.REALLY.1.0~pre0" -import hy.importer +import hy.importer # NOQA +# we import for side-effects. diff --git a/hy/compiler.py b/hy/compiler.py index b2c6f93..4b5ea1c 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -106,34 +106,23 @@ class HyASTCompiler(object): name = "_hy_anon_fn_%d" % (self.anon_fn_count) sig = expression.pop(0) - ret = ast.FunctionDef( - name=name, - lineno=expression.start_line, - col_offset=expression.start_column, - args=ast.arguments( - args=[ - ast.Name( - arg=str(x), - id=str(x), - ctx=ast.Param(), - lineno=x.start_line, - col_offset=x.start_column - ) for x in sig - ], - vararg=None, - kwarg=None, - kwonlyargs=[], - kw_defaults=[], - defaults=[] - ), - body=self._mangle_branch([self.compile(x) for x in expression]), - decorator_list=[] - ) + ret = ast.FunctionDef(name=name, vararg=None, kwarg=None, + kwonlyargs=[], kw_defaults=[], defaults=[], + lineno=expression.start_line, + col_offset=expression.start_column, + args=ast.arguments(args=[ + ast.Name(arg=str(x), id=str(x), + ctx=ast.Param(), + lineno=x.start_line, + col_offset=x.start_column) + for x in sig]), + body=self._mangle_branch([ + self.compile(x) for x in expression]), + decorator_list=[]) self.returnable = ret_status return ret - @builds(HySymbol) def compile_symbol(self, symbol): return ast.Name(id=str(symbol), ctx=ast.Load(), diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index f9f7d6c..bc34f19 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -57,3 +57,9 @@ def test_ast_expression_basics(): )) _ast_spotcheck("value.func.id", code, tree) + + +def test_ast_anon_fns_basics(): + """ Ensure anon fns work. """ + code = hy_compile(tokenize("(fn (x) (* x x))")).body[0] + assert type(code) == ast.FunctionDef