Skip to content

Commit

Permalink
Avoid special-casing pyops in JIT imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed May 10, 2024
1 parent ad8b3c2 commit 1686352
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions hy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __getattr__(self, s):
# to be loaded if they're not needed.

_jit_imports = dict(
pyops=["hy.pyops", None],
read="hy.reader",
read_many="hy.reader",
mangle="hy.reader",
Expand All @@ -50,18 +51,13 @@ def __getattr__(self, s):


def __getattr__(k):
if k == "pyops":
global pyops
import hy.pyops

pyops = hy.pyops
return pyops

if k not in _jit_imports:
raise AttributeError(f"module {__name__!r} has no attribute {k!r}")

v = _jit_imports[k]
module, original_name = v if isinstance(v, list) else (v, k)
import importlib
module = importlib.import_module(module)

globals()[k] = getattr(importlib.import_module(module), original_name)
globals()[k] = getattr(module, original_name) if original_name else module
return globals()[k]

0 comments on commit 1686352

Please sign in to comment.