Skip to content

Commit

Permalink
Fix better
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored Dec 23, 2024
1 parent 18ccd48 commit e9ff949
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,26 @@ def find_module(

if submodule_path is not None:
search_paths = list(submodule_path)
else:
search_paths = sys.path

suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0])
for entry in search_paths:
package_directory = os.path.join(entry, modname)
for suffix in suffixes:
package_file_name = "__init__" + suffix
file_path = os.path.join(package_directory, package_file_name)
if cached_os_path_isfile(file_path):
return ModuleSpec(
name=modname,
location=package_directory,
type=ModuleType.PKG_DIRECTORY,
)
for suffix, type_ in ImportlibFinder._SUFFIXES:
file_name = modname + suffix
file_path = os.path.join(entry, file_name)
if cached_os_path_isfile(file_path):
return ModuleSpec(name=modname, location=file_path, type=type_)
else:
search_paths = sys.path

suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0])
for entry in search_paths:
package_directory = os.path.join(entry, modname)
for suffix in suffixes:
package_file_name = "__init__" + suffix
file_path = os.path.join(package_directory, package_file_name)
if cached_os_path_isfile(file_path):
return ModuleSpec(
name=modname,
location=package_directory,
type=ModuleType.PKG_DIRECTORY,
)
for suffix, type_ in ImportlibFinder._SUFFIXES:
file_name = modname + suffix
file_path = os.path.join(entry, file_name)
if cached_os_path_isfile(file_path):
return ModuleSpec(name=modname, location=file_path, type=type_)

# sys.stdlib_module_names was added in Python 3.10
if PY310_PLUS:
Expand Down

0 comments on commit e9ff949

Please sign in to comment.