From 2a36c1e0c39748250ad3a6c9161fa0a762398a17 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Mon, 31 Dec 2012 14:50:18 -0500 Subject: [PATCH] Close #2 - import-from --- hy/compiler/ast27.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hy/compiler/ast27.py b/hy/compiler/ast27.py index 1ceeff9..edcecf9 100644 --- a/hy/compiler/ast27.py +++ b/hy/compiler/ast27.py @@ -60,6 +60,22 @@ def _ast_import(tree): return ast.Import(names=[ast.alias(name=str(x), asname=None) for x in c]) +def _ast_import_from(tree): + i = tree.get_invocation() + c = i['args'] + mod = c.pop(0) + return ast.ImportFrom( + module=str(mod), + names=[ + ast.alias( + name=str(x), + asname=None + ) for x in c + ], + level=0 + ) + + def _ast_if(node, children, obj): cond = children.pop(0) true = children.pop(0) @@ -132,6 +148,7 @@ class AST27Converter(object): "defn": self._defn, "def": self._def, "import": _ast_import, + "import_from": _ast_import_from, # Remember, "-" --> "_" "while": self._ast_while,