diff --git a/jedi/cache.py b/jedi/cache.py index 7344c8b5..16d8a72b 100644 --- a/jedi/cache.py +++ b/jedi/cache.py @@ -109,7 +109,7 @@ def cache_star_import(func): if mods[0] + settings.star_import_cache_validity > time.time(): return mods[1] # cache is too old and therefore invalid or not available - invalidate_star_import_cache(scope) + _invalidate_star_import_cache_module(scope) mods = func(evaluator, scope, *args, **kwargs) _star_import_cache[scope] = time.time(), mods @@ -117,7 +117,7 @@ def cache_star_import(func): return wrapper -def invalidate_star_import_cache(module, only_main=False): +def _invalidate_star_import_cache_module(module, only_main=False): """ Important if some new modules are being reparsed """ with common.ignored(KeyError): t, mods = _star_import_cache[module] @@ -125,14 +125,25 @@ def invalidate_star_import_cache(module, only_main=False): del _star_import_cache[module] for m in mods: - invalidate_star_import_cache(m, only_main=True) + _invalidate_star_import_cache_module(m, only_main=True) if not only_main: # We need a list here because otherwise the list is being changed # during the iteration in py3k: iteritems -> items. for key, (t, mods) in list(_star_import_cache.items()): if module in mods: - invalidate_star_import_cache(key) + _invalidate_star_import_cache_module(key) + + +def invalidate_star_import_cache(path): + """On success returns True.""" + try: + parser_cache_item = parser_cache[path] + except KeyError: + return False + else: + _invalidate_star_import_cache_module(parser_cache_item.parser.module) + return True def load_parser(path, name): @@ -152,7 +163,7 @@ def load_parser(path, name): # In case there is already a module cached and this module # has to be reparsed, we also need to invalidate the import # caches. - invalidate_star_import_cache(parser_cache_item.parser.module) + _invalidate_star_import_cache_module(parser_cache_item.parser.module) except KeyError: if settings.use_filesystem_cache: return ParserPickling.load_parser(n, p_time) diff --git a/jedi/modules.py b/jedi/modules.py index d2ea84b0..03ec4e9a 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -77,14 +77,10 @@ class ModuleWithCursor(object): def parser(self): """ get the parser lazy """ if not self._parser: - with common.ignored(KeyError): - parser = cache.parser_cache[self.path].parser - cache.invalidate_star_import_cache(parser.module) - # Call the parser already here, because it will be used anyways. - # Also, the position is here important (which will not be used by - # default), therefore fill the cache here. + cache.invalidate_star_import_cache(self.path) self._parser = fast.FastParser(self.source, self.path, self.position) - # don't pickle that module, because it's changing fast + # don't pickle that module, because the main module is changing + # quickly usually. cache.save_parser(self.path, self.name, self._parser, pickling=False) return self._parser