From 66f247aa0b3fe4c5106fce5ab9409eb310d2c856 Mon Sep 17 00:00:00 2001 From: Divyansh Choudhary Date: Thu, 5 Dec 2024 17:07:41 +0530 Subject: [PATCH 1/2] Fix lazy loading of variables This PR fixes lazy imports which broke because the `mang` variable started with `from` instead of the module name causing the imports to not be resolved by the `module_dict` --- lib/python/pyflyby/_dynimp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/python/pyflyby/_dynimp.py b/lib/python/pyflyby/_dynimp.py index 1289358a..a45e4139 100644 --- a/lib/python/pyflyby/_dynimp.py +++ b/lib/python/pyflyby/_dynimp.py @@ -111,8 +111,9 @@ def _add_import(ip, names: str, code: str) -> None: private version of add_import """ assert ip is not None - mang = PYFLYBY_LAZY_LOAD_PREFIX + names.replace(",", "_").replace(" ", "_") - a: FrozenSet[Import] = ImportSet(f"{mang} import {names}")._importset + module = PYFLYBY_LAZY_LOAD_PREFIX.split(" ")[1] + mang = module + names.replace(",", "_").replace(" ", "_") + a: FrozenSet[Import] = ImportSet(f"from {mang} import {names}")._importset b: FrozenSet[Import] = ip._auto_importer.db.known_imports._importset s_import: FrozenSet[Import] = a | b From 84d40cbdf9257bb161b5b1037424305d31d9637f Mon Sep 17 00:00:00 2001 From: Divyansh Choudhary Date: Fri, 6 Dec 2024 13:49:38 +0530 Subject: [PATCH 2/2] Update lib/python/pyflyby/_dynimp.py Co-authored-by: saharan-deshaw --- lib/python/pyflyby/_dynimp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/pyflyby/_dynimp.py b/lib/python/pyflyby/_dynimp.py index a45e4139..cb3149c1 100644 --- a/lib/python/pyflyby/_dynimp.py +++ b/lib/python/pyflyby/_dynimp.py @@ -111,7 +111,7 @@ def _add_import(ip, names: str, code: str) -> None: private version of add_import """ assert ip is not None - module = PYFLYBY_LAZY_LOAD_PREFIX.split(" ")[1] + module = PYFLYBY_LAZY_LOAD_PREFIX.split()[1] mang = module + names.replace(",", "_").replace(" ", "_") a: FrozenSet[Import] = ImportSet(f"from {mang} import {names}")._importset b: FrozenSet[Import] = ip._auto_importer.db.known_imports._importset