Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable auto-import of lazy variables #379

Merged
merged 2 commits into from
Dec 2, 2024
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
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
Loading