diff --git a/hy/compiler.py b/hy/compiler.py index 4b109fb..be5a7a6 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -1122,11 +1122,10 @@ class HyASTCompiler(object): names = [ast.alias(name="*", asname=None)] elif assignments == "ALL": node = asty.Import + prefix = ast_str(prefix, piecewise=True) names = [ast.alias( name=ast_module, - asname=ast_str(prefix) - if prefix and prefix != module - else None)] + asname=prefix if prefix != module else None)] else: node = asty.ImportFrom names = [ diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index d7e7875..04b4d15 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -256,6 +256,14 @@ def test_ast_bad_yield(): cant_compile("(yield 1 2)") +def test_ast_import_mangle_dotted(): + """Mangling a module name with a period shouldn't create a spurious + `asname`.""" + code = can_compile("(import a-b.c)") + assert code.body[0].names[0].name == "a_b.c" + assert code.body[0].names[0].asname is None + + def test_ast_good_import_from(): "Make sure AST can compile valid selective import" can_compile("(import [x [y]])")