[format] Using Black (#7769)

This commit is contained in:
John Bodley
2019-06-25 13:34:48 -07:00
committed by GitHub
parent 0c9e6d0985
commit 5c58fd1802
270 changed files with 15592 additions and 14772 deletions

View File

@@ -22,7 +22,7 @@ from superset import tables_cache
def view_cache_key(*unused_args, **unused_kwargs) -> str:
args_hash = hash(frozenset(request.args.items()))
return 'view/{}/{}'.format(request.path, args_hash)
return "view/{}/{}".format(request.path, args_hash)
def memoized_func(key=view_cache_key, attribute_in_key=None):
@@ -41,27 +41,32 @@ def memoized_func(key=view_cache_key, attribute_in_key=None):
Key is a callable function that takes function arguments and
returns the caching key.
"""
def wrap(f):
if tables_cache:
def wrapped_f(self, *args, **kwargs):
if not kwargs.get('cache', True):
if not kwargs.get("cache", True):
return f(self, *args, **kwargs)
if attribute_in_key:
cache_key = key(*args, **kwargs).format(
getattr(self, attribute_in_key))
getattr(self, attribute_in_key)
)
else:
cache_key = key(*args, **kwargs)
o = tables_cache.get(cache_key)
if not kwargs.get('force') and o is not None:
if not kwargs.get("force") and o is not None:
return o
o = f(self, *args, **kwargs)
tables_cache.set(cache_key, o,
timeout=kwargs.get('cache_timeout'))
tables_cache.set(cache_key, o, timeout=kwargs.get("cache_timeout"))
return o
else:
# noop
def wrapped_f(self, *args, **kwargs):
return f(self, *args, **kwargs)
return wrapped_f
return wrap