1818from collections .abc import Iterable , Iterator , Sequence
1919from functools import lru_cache
2020from pathlib import Path
21- from typing import Any , Literal , NamedTuple , Protocol
21+ from typing import Literal , NamedTuple , Protocol
2222
2323from astroid .const import PY310_PLUS
2424from astroid .modutils import EXT_LIB_DIRS , cached_os_path_isfile
@@ -91,7 +91,7 @@ def __init__(self, path: Sequence[str] | None = None) -> None:
9191 def find_module (
9292 modname : str ,
9393 module_parts : tuple [str ],
94- processed : tuple [str ],
94+ processed : tuple [str , ... ],
9595 submodule_path : Sequence [str ] | None ,
9696 ) -> ModuleSpec | None :
9797 """Find the given module.
@@ -130,7 +130,7 @@ class ImportlibFinder(Finder):
130130 def find_module (
131131 modname : str ,
132132 module_parts : tuple [str ],
133- processed : tuple [str ],
133+ processed : tuple [str , ... ],
134134 submodule_path : Sequence [str ] | None ,
135135 ) -> ModuleSpec | None :
136136 if submodule_path is not None :
@@ -225,7 +225,7 @@ class ExplicitNamespacePackageFinder(ImportlibFinder):
225225 def find_module (
226226 modname : str ,
227227 module_parts : tuple [str ],
228- processed : tuple [str ],
228+ processed : tuple [str , ... ],
229229 submodule_path : Sequence [str ] | None ,
230230 ) -> ModuleSpec | None :
231231 if processed :
@@ -265,7 +265,7 @@ def __init__(self, path: Sequence[str]) -> None:
265265 def find_module (
266266 modname : str ,
267267 module_parts : tuple [str ],
268- processed : tuple [str ],
268+ processed : tuple [str , ... ],
269269 submodule_path : Sequence [str ] | None ,
270270 ) -> ModuleSpec | None :
271271 try :
@@ -289,7 +289,7 @@ class PathSpecFinder(Finder):
289289 def find_module (
290290 modname : str ,
291291 module_parts : tuple [str ],
292- processed : tuple [str ],
292+ processed : tuple [str , ... ],
293293 submodule_path : Sequence [str ] | None ,
294294 ) -> ModuleSpec | None :
295295 spec = importlib .machinery .PathFinder .find_spec (modname , path = submodule_path )
@@ -346,7 +346,7 @@ def _search_zip(
346346) -> tuple [Literal [ModuleType .PY_ZIPMODULE ], str , str ]:
347347 for filepath , importer in _get_zipimporters ():
348348 if PY310_PLUS :
349- found : Any = importer .find_spec (modpath [0 ])
349+ found = importer .find_spec (modpath [0 ])
350350 else :
351351 found = importer .find_module (modpath [0 ])
352352 if found :
@@ -373,15 +373,15 @@ def _find_spec_with_path(
373373 search_path : Sequence [str ],
374374 modname : str ,
375375 module_parts : tuple [str ],
376- processed : tuple [str ],
376+ processed : tuple [str , ... ],
377377 submodule_path : Sequence [str ] | None ,
378378) -> tuple [Finder | _MetaPathFinder , ModuleSpec ]:
379379 for finder in _SPEC_FINDERS :
380380 finder_instance = finder (search_path )
381- spec = finder .find_module (modname , module_parts , processed , submodule_path )
382- if spec is None :
381+ mod_spec = finder .find_module (modname , module_parts , processed , submodule_path )
382+ if mod_spec is None :
383383 continue
384- return finder_instance , spec
384+ return finder_instance , mod_spec
385385
386386 # Support for custom finders
387387 for meta_finder in sys .meta_path :
@@ -444,20 +444,19 @@ def find_spec(modpath: Iterable[str], path: Iterable[str] | None = None) -> Modu
444444
445445
446446@lru_cache (maxsize = 1024 )
447- def _find_spec (module_path : tuple , path : tuple ) -> ModuleSpec :
447+ def _find_spec (module_path : tuple [ str ] , path : tuple [ str , ...] ) -> ModuleSpec :
448448 _path = path or sys .path
449449
450450 # Need a copy for not mutating the argument.
451451 modpath = list (module_path )
452452
453453 submodule_path = None
454- module_parts = tuple (modpath )
455454 processed : list [str ] = []
456455
457456 while modpath :
458457 modname = modpath .pop (0 )
459458 finder , spec = _find_spec_with_path (
460- _path , modname , module_parts , tuple (processed ), submodule_path or path
459+ _path , modname , module_path , tuple (processed ), submodule_path or path
461460 )
462461 processed .append (modname )
463462 if modpath :
0 commit comments