Main Page
Namespaces
Namespace List
Namespace Members
All
_
a
c
d
e
f
g
i
l
m
n
p
r
s
t
u
v
Functions
_
a
c
e
g
l
m
n
p
r
s
t
Variables
Classes
Class List
Class Hierarchy
Class Members
All
_
a
b
c
g
h
l
m
n
p
r
s
t
Functions
Variables
Files
File List
genmypy
_compat.py
Go to the documentation of this file.
1
import
functools
2
3
from
._typing
import
TYPE_CHECKING
4
5
if
TYPE_CHECKING:
6
from
typing
import
Any, Callable, Dict, TypeVar
7
8
TResult = TypeVar(
"TResult"
)
9
10
try
:
11
from
functools
import
lru_cache
# type: ignore
12
except
ImportError:
13
# Provide a simple cache for Python2
14
def
lru_cache
():
15
# type: (...) -> Callable[..., Callable[..., TResult]]
16
def
_lru_cache(func):
17
# type: (Callable[..., TResult]) -> Callable[..., TResult]
18
cache = {}
# type: Dict[Any, Any]
19
20
@functools.wraps(func)
21
def
wrapper(*args):
22
# type: (Any) -> TResult
23
key = tuple(args)
24
if
key
not
in
cache:
25
ret = func(*args)
26
cache[key] = ret
27
else
:
28
ret = cache[key]
29
30
return
ret
31
32
return
wrapper
33
34
return
_lru_cache
genmypy._compat.lru_cache
def lru_cache()
Definition:
_compat.py:14
genmypy
Author(s): Yuki Igarashi, Tamaki Nishino
autogenerated on Mon Apr 10 2023 03:01:12