Skip to content

Commit 7fcfdac

Browse files
committed
Add typing to spec cache
1 parent 2dfce27 commit 7fcfdac

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

astroid/interpreter/_import/spec.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import types
1616
import warnings
1717
import zipimport
18-
from collections.abc import Iterator, Sequence
18+
from collections.abc import Callable, Iterator, Sequence
1919
from pathlib import Path
2020
from typing import Any, Literal, NamedTuple, Protocol
2121

@@ -24,10 +24,10 @@
2424

2525
from . import util
2626

27-
_spec_cache = {}
27+
_spec_cache: dict[str, ModuleSpec] = {}
2828

2929

30-
def clear_spec_cache():
30+
def clear_spec_cache() -> None:
3131
_spec_cache.clear()
3232

3333

@@ -429,11 +429,13 @@ def _find_spec_with_path(
429429
raise ImportError(f"No module named {'.'.join(module_parts)}")
430430

431431

432-
def spec_cache(func):
433-
def wrapper(*args):
434-
key = ".".join(args[0])
432+
def spec_cache(
433+
func: Callable[[list[str], Sequence[str] | None], ModuleSpec]
434+
) -> Callable[..., ModuleSpec]:
435+
def wrapper(modpath: list[str], *args) -> ModuleSpec:
436+
key = ".".join(modpath)
435437
if key not in _spec_cache:
436-
_spec_cache[key] = func(*args)
438+
_spec_cache[key] = func(modpath, *args)
437439

438440
return _spec_cache[key]
439441

0 commit comments

Comments
 (0)