mirror of
https://github.com/LCPQ/quantum_package
synced 2024-08-16 17:48:32 +02:00
27 lines
500 B
Python
27 lines
500 B
Python
from functools import wraps
|
|
|
|
def cache(func):
|
|
"""
|
|
A decorator for lazy evaluation off true function
|
|
"""
|
|
saved = {}
|
|
|
|
@wraps(func)
|
|
def newfunc(*args):
|
|
if args in saved:
|
|
return saved[args]
|
|
|
|
result = func(*args)
|
|
saved[args] = result
|
|
return result
|
|
return newfunc
|
|
|
|
|
|
class classproperty(object):
|
|
|
|
def __init__(self, fget):
|
|
self.fget = fget
|
|
|
|
def __get__(self, owner_self, owner_cls):
|
|
return self.fget(owner_cls)
|