From 6379b070a9b921020e9fc389e3fbe249927214de Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Fri, 3 Jun 2022 14:11:40 -0400 Subject: [PATCH 1/2] Simplify `test_module_prelude` --- tests/compilers/test_ast.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 8e79da323..e2836f8c5 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -636,12 +636,8 @@ 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) + assert x[0].names[0].name == "hy" From f0d07060adc412f42021932ebb5956a28b3db646 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Fri, 3 Jun 2022 14:14:11 -0400 Subject: [PATCH 2/2] Don't redundantly `import hy as hy` This was a regression introduced by 049dcd7d9e2fbca1145ecde5a2e2c83266ff5130. --- hy/compiler.py | 2 +- tests/compilers/test_ast.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index a35169e19..f725cbd90 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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=[]) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index e2836f8c5..ba43aff0a 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -640,4 +640,6 @@ def test_module_prelude(): x = can_compile(code, import_stdlib=True).body assert len(x) == n assert isinstance(x[0], ast.Import) - assert x[0].names[0].name == "hy" + x = x[0].names[0] + assert x.name == "hy" + assert x.asname is None