Skip to content

Commit 14f6175

Browse files
committed
Small if refactor
1 parent ce124b1 commit 14f6175

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Lib/_pyrepl/_module_completer.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,13 @@ def _find_modules(self, path: str, prefix: str) -> list[str]:
114114
# even if a module with the same name would be higher in path
115115
imported_path = (imported_module.__spec__
116116
and imported_module.__spec__.origin)
117-
if imported_path:
118-
if os.path.basename(imported_path) == "__init__.py": # package
119-
imported_path = os.path.dirname(imported_path)
120-
import_location = os.path.dirname(imported_path)
121-
modules = list(pkgutil.iter_modules([import_location]))
122-
else:
123-
# Module already imported but without spec/origin:
124-
# propose no suggestions
117+
if not imported_path:
118+
# Module imported but no spec/origin: propose no suggestions
125119
return []
120+
if os.path.basename(imported_path) == "__init__.py": # package
121+
imported_path = os.path.dirname(imported_path)
122+
import_location = os.path.dirname(imported_path)
123+
modules = list(pkgutil.iter_modules([import_location]))
126124
else:
127125
modules = self.global_cache
128126

0 commit comments

Comments
 (0)