forked from VimPlug/jedi
star_import_cache refactorings: Make it more readable.
This commit is contained in:
@@ -163,33 +163,33 @@ def memoize(func):
|
|||||||
def cache_star_import(func):
|
def cache_star_import(func):
|
||||||
def wrapper(evaluator, scope, *args, **kwargs):
|
def wrapper(evaluator, scope, *args, **kwargs):
|
||||||
with common.ignored(KeyError):
|
with common.ignored(KeyError):
|
||||||
mods = _star_import_cache[scope]
|
start_time, modules = _star_import_cache[scope]
|
||||||
if mods[0] + settings.star_import_cache_validity > time.time():
|
if start_time + settings.star_import_cache_validity > time.time():
|
||||||
return mods[1]
|
return modules
|
||||||
# cache is too old and therefore invalid or not available
|
# cache is too old and therefore invalid or not available
|
||||||
_invalidate_star_import_cache_module(scope)
|
_invalidate_star_import_cache_module(scope)
|
||||||
mods = func(evaluator, scope, *args, **kwargs)
|
modules = func(evaluator, scope, *args, **kwargs)
|
||||||
_star_import_cache[scope] = time.time(), mods
|
_star_import_cache[scope] = time.time(), modules
|
||||||
|
|
||||||
return mods
|
return modules
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def _invalidate_star_import_cache_module(module, only_main=False):
|
def _invalidate_star_import_cache_module(module, only_main=False):
|
||||||
""" Important if some new modules are being reparsed """
|
""" Important if some new modules are being reparsed """
|
||||||
with common.ignored(KeyError):
|
with common.ignored(KeyError):
|
||||||
t, mods = _star_import_cache[module]
|
t, modules = _star_import_cache[module]
|
||||||
|
|
||||||
del _star_import_cache[module]
|
del _star_import_cache[module]
|
||||||
|
|
||||||
for m in mods:
|
for m in modules:
|
||||||
_invalidate_star_import_cache_module(m, only_main=True)
|
_invalidate_star_import_cache_module(m, only_main=True)
|
||||||
|
|
||||||
if not only_main:
|
if not only_main:
|
||||||
# We need a list here because otherwise the list is being changed
|
# We need a list here because otherwise the list is being changed
|
||||||
# during the iteration in py3k: iteritems -> items.
|
# during the iteration in py3k: iteritems -> items.
|
||||||
for key, (t, mods) in list(_star_import_cache.items()):
|
for key, (t, modules) in list(_star_import_cache.items()):
|
||||||
if module in mods:
|
if module in modules:
|
||||||
_invalidate_star_import_cache_module(key)
|
_invalidate_star_import_cache_module(key)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user