diff --git a/jedi/inference/filters.py b/jedi/inference/filters.py index f6af50dc..62782334 100644 --- a/jedi/inference/filters.py +++ b/jedi/inference/filters.py @@ -149,7 +149,7 @@ class ParserTreeFilter(_AbstractUsedNamesFilter): if parent.type == 'trailer': return False base_node = parent if parent.type in ('classdef', 'funcdef') else name - return get_cached_parent_scope(self._used_names, base_node) == self._parser_scope + return get_cached_parent_scope(self._parso_cache_node, base_node) == self._parser_scope def _check_flows(self, names): for name in sorted(names, key=lambda name: name.start_pos, reverse=True): diff --git a/jedi/inference/value/klass.py b/jedi/inference/value/klass.py index 071ec4d5..ee8d4e85 100644 --- a/jedi/inference/value/klass.py +++ b/jedi/inference/value/klass.py @@ -114,7 +114,7 @@ class ClassFilter(ParserTreeFilter): while node is not None: if node == self._parser_scope or node == self.parent_context: return True - node = get_cached_parent_scope(self._used_names, node) + node = get_cached_parent_scope(self._parso_cache_node, node) return False def _access_possible(self, name): diff --git a/jedi/parser_utils.py b/jedi/parser_utils.py index 61f4d491..3c7fa151 100644 --- a/jedi/parser_utils.py +++ b/jedi/parser_utils.py @@ -216,11 +216,14 @@ def is_scope(node): def _get_parent_scope_cache(func): cache = WeakKeyDictionary() - def wrapper(used_names, node, include_flows=False): + def wrapper(parso_cache_node, node, include_flows=False): + if parso_cache_node is None: + return func(node, include_flows) + try: - for_module = cache[used_names] + for_module = cache[parso_cache_node] except KeyError: - for_module = cache[used_names] = {} + for_module = cache[parso_cache_node] = {} try: return for_module[node] @@ -274,6 +277,13 @@ def get_cached_code_lines(grammar, path): def get_parso_cache_node(grammar, path): + """ + This is of course not public. But as long as I control parso, this + shouldn't be a problem. ~ Dave + + The reason for this is mostly caching. This is obviously also a sign of a + broken caching architecture. + """ return parser_cache[grammar._hashed][path] diff --git a/test/test_parso_integration/test_parser_utils.py b/test/test_parso_integration/test_parser_utils.py index 91f04c3f..d29bf751 100644 --- a/test/test_parso_integration/test_parser_utils.py +++ b/test/test_parso_integration/test_parser_utils.py @@ -84,8 +84,5 @@ def test_parser_cache_clear(Script): del parser_cache[script._inference_state.grammar._hashed][script.path] del script - import jedi - jedi.parser_utils.get_cached_parent_scope.__closure__[0].cell_contents.clear() - gc.collect() assert module_id not in [id(m) for m in gc.get_referrers(tree.Module)]