mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Small if refactor
This commit is contained in:
parent
ce124b1f00
commit
14f6175ad1
1 changed files with 6 additions and 8 deletions
|
|
@ -114,15 +114,13 @@ def _find_modules(self, path: str, prefix: str) -> list[str]:
|
||||||
# even if a module with the same name would be higher in path
|
# even if a module with the same name would be higher in path
|
||||||
imported_path = (imported_module.__spec__
|
imported_path = (imported_module.__spec__
|
||||||
and imported_module.__spec__.origin)
|
and imported_module.__spec__.origin)
|
||||||
if imported_path:
|
if not imported_path:
|
||||||
if os.path.basename(imported_path) == "__init__.py": # package
|
# Module imported but no spec/origin: propose no suggestions
|
||||||
imported_path = os.path.dirname(imported_path)
|
|
||||||
import_location = os.path.dirname(imported_path)
|
|
||||||
modules = list(pkgutil.iter_modules([import_location]))
|
|
||||||
else:
|
|
||||||
# Module already imported but without spec/origin:
|
|
||||||
# propose no suggestions
|
|
||||||
return []
|
return []
|
||||||
|
if os.path.basename(imported_path) == "__init__.py": # package
|
||||||
|
imported_path = os.path.dirname(imported_path)
|
||||||
|
import_location = os.path.dirname(imported_path)
|
||||||
|
modules = list(pkgutil.iter_modules([import_location]))
|
||||||
else:
|
else:
|
||||||
modules = self.global_cache
|
modules = self.global_cache
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue