Skip to content

Commit

Permalink
Merge pull request #379 from deshaw/chore/dont-auto-import-lazy-varia…
Browse files Browse the repository at this point in the history
…bles

Disable auto-import of lazy variables
  • Loading branch information
Carreau authored Dec 2, 2024
2 parents 9268cdc + e263594 commit c54822d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/python/pyflyby/_dynimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

module_dict = {}

PYFLYBY_LAZY_LOAD_PREFIX = "from pyflyby_autoimport_"

def add_import(names: str, code: str, *, strict: bool = True):
"""
Expand Down Expand Up @@ -110,8 +111,8 @@ def _add_import(ip, names: str, code: str) -> None:
private version of add_import
"""
assert ip is not None
mang = "pyflyby_autoimport_" + names.replace(",", "_").replace(" ", "_")
a: FrozenSet[Import] = ImportSet(f"from {mang} import {names}")._importset
mang = PYFLYBY_LAZY_LOAD_PREFIX + names.replace(",", "_").replace(" ", "_")
a: FrozenSet[Import] = ImportSet(f"{mang} import {names}")._importset
b: FrozenSet[Import] = ip._auto_importer.db.known_imports._importset
s_import: FrozenSet[Import] = a | b

Expand Down
7 changes: 4 additions & 3 deletions lib/python/pyflyby/_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
auto_import,
clear_failed_imports_cache,
load_symbol)
from pyflyby._dynimp import inject as inject_dynamic_import
from pyflyby._dynimp import (inject as inject_dynamic_import,
PYFLYBY_LAZY_LOAD_PREFIX)
from pyflyby._comms import (initialize_comms, remove_comms,
send_comm_message, MISSING_IMPORTS)
from pyflyby._file import Filename, atomic_write_file, read_file
Expand All @@ -35,7 +36,6 @@
FunctionWithGlobals, NullCtx, advise,
indent)


if False:
__original__ = None # for pyflakes

Expand Down Expand Up @@ -2151,7 +2151,8 @@ def auto_import(
namespaces = get_global_namespaces(self._ip)

def post_import_hook(imp):
send_comm_message(MISSING_IMPORTS, {"missing_imports": str(imp)})
if not str(imp).startswith(PYFLYBY_LAZY_LOAD_PREFIX):
send_comm_message(MISSING_IMPORTS, {"missing_imports": str(imp)})

return self._safe_call(
auto_import, arg=arg, namespaces=namespaces,
Expand Down

0 comments on commit c54822d

Please sign in to comment.