From b9271cf5a53a74160633328c6bfe9fb79be6a0fa Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 26 May 2017 13:43:18 -0400 Subject: [PATCH] Use the parser_cache correctly. --- jedi/evaluate/imports.py | 3 ++- test/test_api/test_api.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index 0e014a53..ebe61106 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -497,7 +497,8 @@ def get_modules_containing_name(evaluator, modules, name): def check_python_file(path): 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: try: return check_fs(path) diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 915534b0..dd5ed6fb 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -13,20 +13,21 @@ from parso import cache def test_preload_modules(): def check_loaded(*modules): # +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 for i in modules: assert [i in k for k in grammar_cache.keys() if k is not None] - temp_cache, cache.parser_cache = cache.parser_cache, {} - parser_cache = cache.parser_cache + old_cache = cache.parser_cache.copy() + cache.parser_cache.clear() - api.preload_module('sys') - check_loaded() # compiled (c_builtin) modules shouldn't be in the cache. - api.preload_module('types', 'token') - check_loaded('types', 'token') - - cache.parser_cache = temp_cache + try: + api.preload_module('sys') + check_loaded() # compiled (c_builtin) modules shouldn't be in the cache. + api.preload_module('types', 'token') + check_loaded('types', 'token') + finally: + cache.parser_cache.update(old_cache) def test_empty_script():