Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ed2776
PyREPL module completion: check for already imported modules
loic-simon Sep 30, 2025
48fd43f
Add blurb
loic-simon Sep 30, 2025
7ac428e
Better convey intent
loic-simon Oct 1, 2025
6515e2f
[TEMP] debug tests on windows using modern technology (print statements)
loic-simon Oct 1, 2025
7dbb906
[TEMP] More debugging, where is my module??
loic-simon Oct 2, 2025
ac3065a
[TEMP] More debugging, where is my module?? (bis)
loic-simon Oct 2, 2025
75a33da
[TEMP] Day 57, deep into debugging, I still don't know where is my mo…
loic-simon Oct 2, 2025
ce124b1
[TEMP] Moar logs
loic-simon Oct 2, 2025
ee7047f
Merge branch 'main' into pyrepl-module-completion-check-for-already-i…
loic-simon Oct 3, 2025
3f362cd
[TEMP] Is it a FileFinder cache issue??
loic-simon Oct 3, 2025
ed8ce73
[TEMP] Looks like a cache issue indeed
loic-simon Oct 3, 2025
19c49bb
Tests: clean FileFinder cache
loic-simon Oct 3, 2025
16e44af
Remove all debugging junk
loic-simon Oct 3, 2025
14f6175
Small if refactor
loic-simon Oct 5, 2025
bdd7bdf
Merge branch 'pyrepl-module-completion-check-for-already-imported-mod…
loic-simon Oct 5, 2025
78e4737
Full test coverage for new code
loic-simon Oct 11, 2025
e3f1ddb
Merge branch 'python:main' into pyrepl-module-completion-check-for-al…
loic-simon Oct 11, 2025
2644400
Merge branch 'main' into pyrepl-module-completion-check-for-already-i…
tomasr8 Dec 28, 2025
5fa70cf
Merge branch 'main' into pyrepl-module-completion-check-for-already-i…
loic-simon Jan 1, 2026
d332e14
Check __spec__.has_location + refactor
loic-simon Jan 1, 2026
1a5327c
Rename private helper
loic-simon Jan 1, 2026
d48f243
Simplify implementation
loic-simon Jan 2, 2026
e235e20
Fix find_spec call
loic-simon Jan 2, 2026
f6757fe
Remove unused import
loic-simon Jan 2, 2026
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
Prev Previous commit
Next Next commit
Remove all debugging junk
  • Loading branch information
loic-simon committed Oct 3, 2025
commit 16e44afeb7b5d123b94e507a531e13829dfd9be1
68 changes: 0 additions & 68 deletions Lib/_pyrepl/_module_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,12 @@ def _find_modules(self, path: str, prefix: str) -> list[str]:
for segment in path.split('.'):
modules = [mod_info for mod_info in modules
if mod_info.ispkg and mod_info.name == segment]
print(f"{segment=}, {modules=}") # TEMPORARY -- debugging tests on windows
if is_stdlib_import is None:
# Top-level import decide if we import from stdlib or not
is_stdlib_import = all(
self._is_stdlib_module(mod_info) for mod_info in modules
)
modules = self.iter_submodules(modules)
modules = list(modules) # TEMPORARY -- debugging tests on windows
print(f"segment=last, {modules=}") # TEMPORARY -- debugging tests on windows

module_names = [module.name for module in modules]
if is_stdlib_import:
Expand Down Expand Up @@ -217,72 +214,7 @@ def global_cache(self) -> list[pkgutil.ModuleInfo]:
"""Global module cache"""
if not self._global_cache or self._curr_sys_path != sys.path:
self._curr_sys_path = sys.path[:]
print('getting packages/') # TEMPORARY -- debugging tests on windows
self._global_cache = list(pkgutil.iter_modules())
# === BEGIN TEMPORARY -- debugging tests on windows ===
mymod = next((p for p in self._global_cache if p.name == "mymodule"), None)
if mymod:
print("0a", mymod)
import glob
print("files on finder path:", glob.glob("**", root_dir=mymod.module_finder.path, recursive=True))
spec = mymod.module_finder.find_spec(mymod.name, None)
print("found spec:", spec)
mymod.module_finder.invalidate_caches()
not_cached_spec = mymod.module_finder.find_spec(mymod.name, None)
print("found spec after invalidate:", not_cached_spec)
if spec:
print("1")
assert spec.submodule_search_locations and len(spec.submodule_search_locations) == 1
print("2")
importer = pkgutil.get_importer(spec.submodule_search_locations[0])
print("3")
assert importer and isinstance(importer, FileFinder)
print("4")
if importer.path is None or not os.path.isdir(importer.path):
print("4a")
return
yielded = {}
import inspect
try:
filenames = os.listdir(importer.path)
except OSError:
# ignore unreadable directories like import does
print("4b")
filenames = []
print("4c", filenames)
filenames.sort() # handle packages before same-named modules
submods = []
for fn in filenames:
print("4d", fn)
modname = inspect.getmodulename(fn)
print("4e", modname)
if modname=='__init__' or modname in yielded:
print("4f", modname)
continue
path = os.path.join(importer.path, fn)
ispkg = False
if not modname and os.path.isdir(path) and '.' not in fn:
print("4g")
modname = fn
try:
dircontents = os.listdir(path)
except OSError:
# ignore unreadable directories like import does
dircontents = []
for fn in dircontents:
subname = inspect.getmodulename(fn)
if subname=='__init__':
ispkg = True
break
else:
continue # not a package
if modname and '.' not in modname:
print("4h")
yielded[modname] = 1
submods.append((importer, modname, ispkg))
print("4i")
print("module:", mymod, submods)
# === END TEMPORARY ===
return self._global_cache


Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,6 @@ def test_already_imported_custom_module_no_other_suggestions(self):
self.assertEqual(output, "import mymodule.foo")

del sys.modules["mymodule"]
print(f"{dir1=}, {dir2=}") # TEMPORARY -- debugging tests on windows
print(f"{[p.relative_to(dir1) for p in dir1.glob("**")]=}") # TEMPORARY -- debugging tests on windows
print(f"{[p.relative_to(dir2) for p in dir2.glob("**")]=}") # TEMPORARY -- debugging tests on windows
# mymodule not imported anymore -> suggest dir2 submodules
events = code_to_events("import mymodule.\t\n")
reader = self.prepare_reader(events, namespace={})
Expand Down
Loading