Fix a regression with mangling module names

This commit is contained in:
Kodi Arfer 2018-05-20 14:55:23 -07:00
parent d16a0bb395
commit a38c948ed2
2 changed files with 10 additions and 3 deletions

View File

@ -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 = [

View File

@ -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]])")