From 96c1671f7f0aa7265052f36157fedcb53a0ed336 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sun, 24 May 2026 10:26:07 -0400 Subject: [PATCH 1/2] Use `monkeypatch` for editing `sys.path` in a test --- tests/importer/test_importer.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index d73bbc2c0..5d7b1371c 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -274,18 +274,15 @@ def test_filtered_importlib_frames(capsys): assert "importlib._" not in captured_w_filtering -def test_zipimport(tmp_path): +def test_zipimport(tmp_path, monkeypatch): from zipfile import ZipFile zpath = tmp_path / "archive.zip" with ZipFile(zpath, "w") as o: o.writestr("example.hy", '(setv x "Hy from ZIP")') - try: - sys.path.insert(0, str(zpath)) - import example - finally: - sys.path = [p for p in sys.path if p != str(zpath)] + monkeypatch.syspath_prepend(zpath) + import example assert example.x == "Hy from ZIP" assert example.__file__ == str(zpath / "example.hy") From 7dcc78fb82e9d6a836d4a08362c08da55d0051f8 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sun, 24 May 2026 10:31:46 -0400 Subject: [PATCH 2/2] Fix a regression in import of Python from ZIPs --- NEWS.rst | 10 ++++++++++ hy/importer.py | 5 ++++- tests/importer/test_importer.py | 13 +++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index ca65b012c..f8f4681ca 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,16 @@ Hy is `semantically versioned `__ since 1.0.0. +Unreleased +====================================================================== + +Supports Python 3.x – Python 3.y + +Bug Fixes +------------------------------ +* Fixed a regression in Hy 1.3.0 that could prevent imports of Python + code in ZIP archives. + 1.3.0 ("Dogs Should Be Raw", released 2026-05-24) ====================================================================== diff --git a/hy/importer.py b/hy/importer.py index 7f327e490..d33d913f0 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -146,7 +146,10 @@ def _hy_source_to_code(self, data, path, fullname=None, _optimize=-1): def _hy_compile_source(pathname, source, module=None): if not pathname.endswith(".hy"): - return _py_compile_source(pathname, source, module) + return _py_compile_source( + pathname, + source, + *([module] if hy.compat.PY3_15 else [])) mname = f"" sys.modules[mname] = types.ModuleType(mname) return compile( diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index 5d7b1371c..da9162bd5 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -279,12 +279,17 @@ def test_zipimport(tmp_path, monkeypatch): zpath = tmp_path / "archive.zip" with ZipFile(zpath, "w") as o: - o.writestr("example.hy", '(setv x "Hy from ZIP")') + # Test a Python module as well as a Hy module to ensure that + # Hy's edits to ZIP imports can still get Python files. + o.writestr("zip_py.py", 'x = "Py from ZIP"') + o.writestr("zip_hy.hy", '(setv x "Hy from ZIP")') monkeypatch.syspath_prepend(zpath) - import example - assert example.x == "Hy from ZIP" - assert example.__file__ == str(zpath / "example.hy") + import zip_py, zip_hy + assert zip_py.x == "Py from ZIP" + assert zip_py.__file__ == str(zpath / "zip_py.py") + assert zip_hy.x == "Hy from ZIP" + assert zip_hy.__file__ == str(zpath / "zip_hy.hy") def test_eval_requiring_macro():