]>
Commit | Line | Data |
---|---|---|
53e6db90 DC |
1 | from typing import Dict, Tuple, Callable |
2 | ||
3 | CacheValues = Tuple[str, str, str] | |
4 | CacheValuesCallback = Callable[[], CacheValues] | |
5 | ||
6 | ||
7 | _cache: Dict[str, Dict[str, CacheValues]] = {} | |
8 | ||
9 | ||
10 | def save_entry(module_name: str, name: str, cache: CacheValues) -> None: | |
11 | try: | |
12 | module_cache = _cache[module_name] | |
13 | except KeyError: | |
14 | module_cache = _cache[module_name] = {} | |
15 | module_cache[name] = cache | |
16 | ||
17 | ||
18 | def _create_get_from_cache(number: int) -> Callable[[str, str, CacheValuesCallback], str]: | |
19 | def _get_from_cache(module_name: str, name: str, get_cache_values: CacheValuesCallback) -> str: | |
20 | try: | |
21 | return _cache[module_name][name][number] | |
22 | except KeyError: | |
23 | v = get_cache_values() | |
24 | save_entry(module_name, name, v) | |
25 | return v[number] | |
26 | return _get_from_cache | |
27 | ||
28 | ||
29 | get_type = _create_get_from_cache(0) | |
30 | get_docstring_signature = _create_get_from_cache(1) | |
31 | get_docstring = _create_get_from_cache(2) |