18
18
from collections .abc import Iterable , Iterator , Sequence
19
19
from functools import lru_cache
20
20
from pathlib import Path
21
- from typing import Any , Literal , NamedTuple , Protocol
21
+ from typing import Literal , NamedTuple , Protocol
22
22
23
23
from astroid .const import PY310_PLUS
24
24
from astroid .modutils import EXT_LIB_DIRS , cached_os_path_isfile
@@ -91,7 +91,7 @@ def __init__(self, path: Sequence[str] | None = None) -> None:
91
91
def find_module (
92
92
modname : str ,
93
93
module_parts : tuple [str ],
94
- processed : tuple [str ],
94
+ processed : tuple [str , ... ],
95
95
submodule_path : Sequence [str ] | None ,
96
96
) -> ModuleSpec | None :
97
97
"""Find the given module.
@@ -130,7 +130,7 @@ class ImportlibFinder(Finder):
130
130
def find_module (
131
131
modname : str ,
132
132
module_parts : tuple [str ],
133
- processed : tuple [str ],
133
+ processed : tuple [str , ... ],
134
134
submodule_path : Sequence [str ] | None ,
135
135
) -> ModuleSpec | None :
136
136
if submodule_path is not None :
@@ -225,7 +225,7 @@ class ExplicitNamespacePackageFinder(ImportlibFinder):
225
225
def find_module (
226
226
modname : str ,
227
227
module_parts : tuple [str ],
228
- processed : tuple [str ],
228
+ processed : tuple [str , ... ],
229
229
submodule_path : Sequence [str ] | None ,
230
230
) -> ModuleSpec | None :
231
231
if processed :
@@ -265,7 +265,7 @@ def __init__(self, path: Sequence[str]) -> None:
265
265
def find_module (
266
266
modname : str ,
267
267
module_parts : tuple [str ],
268
- processed : tuple [str ],
268
+ processed : tuple [str , ... ],
269
269
submodule_path : Sequence [str ] | None ,
270
270
) -> ModuleSpec | None :
271
271
try :
@@ -289,7 +289,7 @@ class PathSpecFinder(Finder):
289
289
def find_module (
290
290
modname : str ,
291
291
module_parts : tuple [str ],
292
- processed : tuple [str ],
292
+ processed : tuple [str , ... ],
293
293
submodule_path : Sequence [str ] | None ,
294
294
) -> ModuleSpec | None :
295
295
spec = importlib .machinery .PathFinder .find_spec (modname , path = submodule_path )
@@ -346,7 +346,7 @@ def _search_zip(
346
346
) -> tuple [Literal [ModuleType .PY_ZIPMODULE ], str , str ]:
347
347
for filepath , importer in _get_zipimporters ():
348
348
if PY310_PLUS :
349
- found : Any = importer .find_spec (modpath [0 ])
349
+ found = importer .find_spec (modpath [0 ])
350
350
else :
351
351
found = importer .find_module (modpath [0 ])
352
352
if found :
@@ -373,15 +373,15 @@ def _find_spec_with_path(
373
373
search_path : Sequence [str ],
374
374
modname : str ,
375
375
module_parts : tuple [str ],
376
- processed : tuple [str ],
376
+ processed : tuple [str , ... ],
377
377
submodule_path : Sequence [str ] | None ,
378
378
) -> tuple [Finder | _MetaPathFinder , ModuleSpec ]:
379
379
for finder in _SPEC_FINDERS :
380
380
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 :
383
383
continue
384
- return finder_instance , spec
384
+ return finder_instance , mod_spec
385
385
386
386
# Support for custom finders
387
387
for meta_finder in sys .meta_path :
@@ -444,20 +444,19 @@ def find_spec(modpath: Iterable[str], path: Iterable[str] | None = None) -> Modu
444
444
445
445
446
446
@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 :
448
448
_path = path or sys .path
449
449
450
450
# Need a copy for not mutating the argument.
451
451
modpath = list (module_path )
452
452
453
453
submodule_path = None
454
- module_parts = tuple (modpath )
455
454
processed : list [str ] = []
456
455
457
456
while modpath :
458
457
modname = modpath .pop (0 )
459
458
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
461
460
)
462
461
processed .append (modname )
463
462
if modpath :
0 commit comments