Skip to content

Commit

Permalink
Merge pull request #2300 from Kodiologist/hy-as-hy
Browse files Browse the repository at this point in the history
Don't redundantly `import hy as hy`
  • Loading branch information
Kodiologist authored Jun 6, 2022
2 parents 02e02c2 + f0d0706 commit bdd5d1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def hy_compile(

# Import hy for runtime.
if import_stdlib:
body.append(ast.fix_missing_locations(ast.Import([ast.alias("hy", "hy")])))
body.append(ast.fix_missing_locations(ast.Import([ast.alias("hy", None)])))

body += result.stmts
ret = root(body=body, type_ignores=[])
Expand Down
16 changes: 7 additions & 9 deletions tests/compilers/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,10 @@ def test_models_accessible():

def test_module_prelude():
"""Make sure the hy prelude appears at the top of a compiled module."""
hy_ast = can_compile("", import_stdlib=True)
assert len(hy_ast.body) == 1
assert isinstance(hy_ast.body[0], ast.Import)
assert hy_ast.body[0].names[0].name == "hy"

hy_ast = can_compile("(setv flag (- hy.models.Symbol 1))", import_stdlib=True)
assert len(hy_ast.body) == 2
assert isinstance(hy_ast.body[0], ast.Import)
assert hy_ast.body[0].names[0].name == "hy"
for code, n in ("", 1), ("(setv flag (- hy.models.Symbol 1))", 2):
x = can_compile(code, import_stdlib=True).body
assert len(x) == n
assert isinstance(x[0], ast.Import)
x = x[0].names[0]
assert x.name == "hy"
assert x.asname is None

0 comments on commit bdd5d1f

Please sign in to comment.