Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Hy is `semantically versioned <https://semver.org/>`__ 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)
======================================================================

Expand Down
5 changes: 4 additions & 1 deletion hy/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<zip:{pathname}>"
sys.modules[mname] = types.ModuleType(mname)
return compile(
Expand Down
22 changes: 12 additions & 10 deletions tests/importer/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,22 @@ 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)]
assert example.x == "Hy from ZIP"
assert example.__file__ == str(zpath / "example.hy")
# 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 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():
Expand Down
Loading