1
0
forked from VimPlug/jedi

Use the parser_cache correctly.

This commit is contained in:
Dave Halter
2017-05-26 13:43:18 -04:00
parent 76529ca34d
commit b9271cf5a5
2 changed files with 12 additions and 10 deletions

View File

@@ -497,7 +497,8 @@ def get_modules_containing_name(evaluator, modules, name):
def check_python_file(path): def check_python_file(path):
try: try:
node_cache_item = parser_cache[path] # TODO I don't think we should use the cache here?!
node_cache_item = parser_cache[evaluator.grammar._hashed][path]
except KeyError: except KeyError:
try: try:
return check_fs(path) return check_fs(path)

View File

@@ -13,20 +13,21 @@ from parso import cache
def test_preload_modules(): def test_preload_modules():
def check_loaded(*modules): def check_loaded(*modules):
# +1 for None module (currently used) # +1 for None module (currently used)
grammar_cache = next(iter(parser_cache.values())) grammar_cache = next(iter(cache.parser_cache.values()))
assert len(grammar_cache) == len(modules) + 1 assert len(grammar_cache) == len(modules) + 1
for i in modules: for i in modules:
assert [i in k for k in grammar_cache.keys() if k is not None] assert [i in k for k in grammar_cache.keys() if k is not None]
temp_cache, cache.parser_cache = cache.parser_cache, {} old_cache = cache.parser_cache.copy()
parser_cache = cache.parser_cache cache.parser_cache.clear()
api.preload_module('sys') try:
check_loaded() # compiled (c_builtin) modules shouldn't be in the cache. api.preload_module('sys')
api.preload_module('types', 'token') check_loaded() # compiled (c_builtin) modules shouldn't be in the cache.
check_loaded('types', 'token') api.preload_module('types', 'token')
check_loaded('types', 'token')
cache.parser_cache = temp_cache finally:
cache.parser_cache.update(old_cache)
def test_empty_script(): def test_empty_script():