Skip to content

Commit

Permalink
Add typing to spec cache
Browse files Browse the repository at this point in the history
  • Loading branch information
crazybolillo committed Apr 9, 2024
1 parent 2dfce27 commit 7fcfdac
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import types
import warnings
import zipimport
from collections.abc import Iterator, Sequence
from collections.abc import Callable, Iterator, Sequence
from pathlib import Path
from typing import Any, Literal, NamedTuple, Protocol

Expand All @@ -24,10 +24,10 @@

from . import util

_spec_cache = {}
_spec_cache: dict[str, ModuleSpec] = {}


def clear_spec_cache():
def clear_spec_cache() -> None:
_spec_cache.clear()


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


def spec_cache(func):
def wrapper(*args):
key = ".".join(args[0])
def spec_cache(
func: Callable[[list[str], Sequence[str] | None], ModuleSpec]
) -> Callable[..., ModuleSpec]:
def wrapper(modpath: list[str], *args) -> ModuleSpec:
key = ".".join(modpath)
if key not in _spec_cache:
_spec_cache[key] = func(*args)
_spec_cache[key] = func(modpath, *args)

return _spec_cache[key]

Expand Down

0 comments on commit 7fcfdac

Please sign in to comment.