From d8ff00f31c581a49b5f884b3d250f496a6f90b54 Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:24:05 -0400 Subject: [PATCH 1/2] Make Finder.find_module static to facilitate future caching --- astroid/interpreter/_import/spec.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py index d2dc13bfc8..c5c1333e4a 100644 --- a/astroid/interpreter/_import/spec.py +++ b/astroid/interpreter/_import/spec.py @@ -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], @@ -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], @@ -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], @@ -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], @@ -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], @@ -378,7 +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( + spec = finder.find_module( modname, module_parts, processed, submodule_path ) if spec is None: From f35ab42017667806bbb15607f78cc783d7a4b3cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:44:10 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- astroid/interpreter/_import/spec.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py index c5c1333e4a..d30e8c1109 100644 --- a/astroid/interpreter/_import/spec.py +++ b/astroid/interpreter/_import/spec.py @@ -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.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