Merge pull request #1613 from Kodiologist/modname-mangle-bug

Fix a regression with mangling module names
This commit is contained in:
Kodi Arfer 2018-06-03 15:44:40 -07:00 committed by GitHub
commit aae1f8718c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -1122,11 +1122,10 @@ class HyASTCompiler(object):
names = [ast.alias(name="*", asname=None)] names = [ast.alias(name="*", asname=None)]
elif assignments == "ALL": elif assignments == "ALL":
node = asty.Import node = asty.Import
prefix = ast_str(prefix, piecewise=True)
names = [ast.alias( names = [ast.alias(
name=ast_module, name=ast_module,
asname=ast_str(prefix) asname=prefix if prefix != module else None)]
if prefix and prefix != module
else None)]
else: else:
node = asty.ImportFrom node = asty.ImportFrom
names = [ names = [

View File

@ -256,6 +256,14 @@ def test_ast_bad_yield():
cant_compile("(yield 1 2)") 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(): def test_ast_good_import_from():
"Make sure AST can compile valid selective import" "Make sure AST can compile valid selective import"
can_compile("(import [x [y]])") can_compile("(import [x [y]])")