From db88fcd347b8e362361974ac8b41b7e94b7cbc6c Mon Sep 17 00:00:00 2001 From: Amrut Joshi Date: Tue, 19 Mar 2013 05:33:45 +0000 Subject: [PATCH] Support for "import as" --- hy/compiler.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index 4852d7e..b032550 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -224,6 +224,16 @@ class HyASTCompiler(object): col_offset=expr.start_column, names=[ast.alias(name=str(x), asname=None) for x in expr]) + @builds("import_as") + def compile_import_as_expression(self, expr): + expr.pop(0) # index + modlist = [expr[i:i+2] for i in range(0, len(expr), 2)] + return ast.Import( + lineno=expr.start_line, + col_offset=expr.start_column, + module=str(expr.pop(0)), + names=[ast.alias(name=str(x[0]), asname=str(x[1])) for x in modlist]) + @builds("import_from") def compile_import_from_expression(self, expr): expr.pop(0) # index