Pull out if statement from for loop

This commit is contained in:
Erik Johnston 2017-05-22 15:12:19 +01:00
parent e3417a06e2
commit bd7bb5df71

View File

@ -471,14 +471,22 @@ class CacheListDescriptor(_CacheDescriptorBase):
results = {}
cached_defers = {}
missing = []
for arg in list_args:
try:
# If the cache takes a single arg then that is used as the key,
# otherwise a tuple is used.
if num_args == 1:
res = cache.get(arg, callback=invalidate_callback)
def cache_get(arg):
return cache.get(arg, callback=invalidate_callback)
else:
key = list(keyargs)
def cache_get(arg):
key[self.list_pos] = arg
res = cache.get(tuple(key), callback=invalidate_callback)
return cache.get(tuple(key), callback=invalidate_callback)
for arg in list_args:
try:
res = cache_get(arg)
if not isinstance(res, ObservableDeferred):
results[arg] = res