Skip to content

Commit 8584096

Browse files
committed
Turn everything around
1 parent 0a5c16b commit 8584096

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

astroid/interpreter/_import/spec.py

+23-22
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,29 @@ def find_module(
142142
type=ModuleType.C_BUILTIN,
143143
)
144144

145+
if submodule_path is not None:
146+
search_paths = list(submodule_path)
147+
else:
148+
search_paths = sys.path
149+
150+
suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0])
151+
for entry in search_paths:
152+
package_directory = os.path.join(entry, modname)
153+
for suffix in suffixes:
154+
package_file_name = "__init__" + suffix
155+
file_path = os.path.join(package_directory, package_file_name)
156+
if os.path.isfile(file_path):
157+
return ModuleSpec(
158+
name=modname,
159+
location=package_directory,
160+
type=ModuleType.PKG_DIRECTORY,
161+
)
162+
for suffix, type_ in ImportlibFinder._SUFFIXES:
163+
file_name = modname + suffix
164+
file_path = os.path.join(entry, file_name)
165+
if os.path.isfile(file_path):
166+
return ModuleSpec(name=modname, location=file_path, type=type_)
167+
145168
# sys.stdlib_module_names was added in Python 3.10
146169
if PY310_PLUS:
147170
# If the module is a stdlib module, check whether this is a frozen module. Note that
@@ -194,28 +217,6 @@ def find_module(
194217
except ValueError:
195218
pass
196219

197-
if submodule_path is not None:
198-
search_paths = list(submodule_path)
199-
else:
200-
search_paths = sys.path
201-
202-
suffixes = (".py", ".pyi", importlib.machinery.BYTECODE_SUFFIXES[0])
203-
for entry in search_paths:
204-
package_directory = os.path.join(entry, modname)
205-
for suffix in suffixes:
206-
package_file_name = "__init__" + suffix
207-
file_path = os.path.join(package_directory, package_file_name)
208-
if os.path.isfile(file_path):
209-
return ModuleSpec(
210-
name=modname,
211-
location=package_directory,
212-
type=ModuleType.PKG_DIRECTORY,
213-
)
214-
for suffix, type_ in ImportlibFinder._SUFFIXES:
215-
file_name = modname + suffix
216-
file_path = os.path.join(entry, file_name)
217-
if os.path.isfile(file_path):
218-
return ModuleSpec(name=modname, location=file_path, type=type_)
219220
return None
220221

221222
def contribute_to_path(

0 commit comments

Comments
 (0)