Skip to content

Commit b312b56

Browse files
authored
Make Finder.find_module static to facilitate future caching (#2509)
1 parent 8515010 commit b312b56

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

astroid/interpreter/_import/spec.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class Finder:
8686
def __init__(self, path: Sequence[str] | None = None) -> None:
8787
self._path = path or sys.path
8888

89+
@staticmethod
8990
@abc.abstractmethod
9091
def find_module(
91-
self,
9292
modname: str,
9393
module_parts: Sequence[str],
9494
processed: list[str],
@@ -126,8 +126,8 @@ class ImportlibFinder(Finder):
126126
+ [(s, ModuleType.PY_COMPILED) for s in importlib.machinery.BYTECODE_SUFFIXES]
127127
)
128128

129+
@staticmethod
129130
def find_module(
130-
self,
131131
modname: str,
132132
module_parts: Sequence[str],
133133
processed: list[str],
@@ -221,8 +221,8 @@ def contribute_to_path(
221221
class ExplicitNamespacePackageFinder(ImportlibFinder):
222222
"""A finder for the explicit namespace packages."""
223223

224+
@staticmethod
224225
def find_module(
225-
self,
226226
modname: str,
227227
module_parts: Sequence[str],
228228
processed: list[str],
@@ -261,8 +261,8 @@ def __init__(self, path: Sequence[str]) -> None:
261261
except zipimport.ZipImportError:
262262
continue
263263

264+
@staticmethod
264265
def find_module(
265-
self,
266266
modname: str,
267267
module_parts: Sequence[str],
268268
processed: list[str],
@@ -285,8 +285,8 @@ def find_module(
285285
class PathSpecFinder(Finder):
286286
"""Finder based on importlib.machinery.PathFinder."""
287287

288+
@staticmethod
288289
def find_module(
289-
self,
290290
modname: str,
291291
module_parts: Sequence[str],
292292
processed: list[str],
@@ -378,9 +378,7 @@ def _find_spec_with_path(
378378
) -> tuple[Finder | _MetaPathFinder, ModuleSpec]:
379379
for finder in _SPEC_FINDERS:
380380
finder_instance = finder(search_path)
381-
spec = finder_instance.find_module(
382-
modname, module_parts, processed, submodule_path
383-
)
381+
spec = finder.find_module(modname, module_parts, processed, submodule_path)
384382
if spec is None:
385383
continue
386384
return finder_instance, spec

0 commit comments

Comments
 (0)