mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
...
This commit is contained in:
parent
368f228173
commit
a23d100265
@ -1,9 +1,19 @@
|
|||||||
def cache(f):
|
# def cache(f):
|
||||||
def wrapper(*args):
|
# def wrapper(*args):
|
||||||
if not hasattr(f, '__cache__'):
|
# if not hasattr(f, '__cache__'):
|
||||||
f.__cache__ = {}
|
# f.__cache__ = {}
|
||||||
key = args
|
# key = args
|
||||||
if key not in f.__cache__:
|
# if key not in f.__cache__:
|
||||||
f.__cache__[key] = f(*args)
|
# f.__cache__[key] = f(*args)
|
||||||
return f.__cache__[key]
|
# return f.__cache__[key]
|
||||||
return wrapper
|
# return wrapper
|
||||||
|
|
||||||
|
class cache:
|
||||||
|
def __init__(self, f):
|
||||||
|
self.f = f
|
||||||
|
self.cache = {}
|
||||||
|
|
||||||
|
def __call__(self, *args):
|
||||||
|
if args not in self.cache:
|
||||||
|
self.cache[args] = self.f(*args)
|
||||||
|
return self.cache[args]
|
@ -1,4 +1,4 @@
|
|||||||
class Placeholder:
|
class _Placeholder:
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
def __getitem__(self, *args, **kwargs):
|
def __getitem__(self, *args, **kwargs):
|
||||||
@ -7,7 +7,7 @@ class Placeholder:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
_PLACEHOLDER = Placeholder()
|
_PLACEHOLDER = _Placeholder()
|
||||||
|
|
||||||
List = _PLACEHOLDER
|
List = _PLACEHOLDER
|
||||||
Dict = _PLACEHOLDER
|
Dict = _PLACEHOLDER
|
||||||
|
Loading…
x
Reference in New Issue
Block a user