Skip to content

Commit

Permalink
Make Finder.find_module static to facilitate future caching (#2509)
Browse files Browse the repository at this point in the history
  • Loading branch information
correctmost committed Aug 18, 2024
1 parent 8515010 commit b312b56
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class Finder:
def __init__(self, path: Sequence[str] | None = None) -> None:
self._path = path or sys.path

@staticmethod
@abc.abstractmethod
def find_module(
self,
modname: str,
module_parts: Sequence[str],
processed: list[str],
Expand Down Expand Up @@ -126,8 +126,8 @@ class ImportlibFinder(Finder):
+ [(s, ModuleType.PY_COMPILED) for s in importlib.machinery.BYTECODE_SUFFIXES]
)

@staticmethod
def find_module(
self,
modname: str,
module_parts: Sequence[str],
processed: list[str],
Expand Down Expand Up @@ -221,8 +221,8 @@ def contribute_to_path(
class ExplicitNamespacePackageFinder(ImportlibFinder):
"""A finder for the explicit namespace packages."""

@staticmethod
def find_module(
self,
modname: str,
module_parts: Sequence[str],
processed: list[str],
Expand Down Expand Up @@ -261,8 +261,8 @@ def __init__(self, path: Sequence[str]) -> None:
except zipimport.ZipImportError:
continue

@staticmethod
def find_module(
self,
modname: str,
module_parts: Sequence[str],
processed: list[str],
Expand All @@ -285,8 +285,8 @@ def find_module(
class PathSpecFinder(Finder):
"""Finder based on importlib.machinery.PathFinder."""

@staticmethod
def find_module(
self,
modname: str,
module_parts: Sequence[str],
processed: list[str],
Expand Down Expand Up @@ -378,9 +378,7 @@ def _find_spec_with_path(
) -> tuple[Finder | _MetaPathFinder, ModuleSpec]:
for finder in _SPEC_FINDERS:
finder_instance = finder(search_path)
spec = finder_instance.find_module(
modname, module_parts, processed, submodule_path
)
spec = finder.find_module(modname, module_parts, processed, submodule_path)
if spec is None:
continue
return finder_instance, spec
Expand Down

0 comments on commit b312b56

Please sign in to comment.