Skip to content
Snippets Groups Projects

Use get_type_of_expression in typing_form_sympy_inspection to infer types

Files
5
+ 18
0
import os
import os
 
from collections import Hashable
 
from functools import partial
 
from itertools import chain
try:
try:
from functools import lru_cache as memorycache
from functools import lru_cache as memorycache
except ImportError:
except ImportError:
from backports.functools_lru_cache import lru_cache as memorycache
from backports.functools_lru_cache import lru_cache as memorycache
 
try:
try:
from joblib import Memory
from joblib import Memory
from appdirs import user_cache_dir
from appdirs import user_cache_dir
@@ -22,6 +26,20 @@ except ImportError:
@@ -22,6 +26,20 @@ except ImportError:
return o
return o
 
def _wrapper(wrapped_func, cached_func, *args, **kwargs):
 
if all(isinstance(a, Hashable) for a in chain(args, kwargs.values())):
 
return cached_func(*args, **kwargs)
 
else:
 
return wrapped_func(*args, **kwargs)
 
 
 
def memorycache_if_hashable(maxsize=128, typed=False):
 
 
def wrapper(func):
 
return partial(_wrapper, func, memorycache(maxsize, typed)(func))
 
 
return wrapper
 
# Disable memory cache:
# Disable memory cache:
# disk_cache = lambda o: o
# disk_cache = lambda o: o
# disk_cache_no_fallback = lambda o: o
# disk_cache_no_fallback = lambda o: o
Loading