mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
Avoid caching parso objects, fixes #1723
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import gc
|
||||
from pathlib import Path
|
||||
|
||||
from jedi import parser_utils
|
||||
from parso import parse
|
||||
from parso.cache import parser_cache
|
||||
from parso.python import tree
|
||||
|
||||
import pytest
|
||||
@@ -67,3 +71,21 @@ def test_get_signature(code, signature):
|
||||
if node.type == 'simple_stmt':
|
||||
node = node.children[0]
|
||||
assert parser_utils.get_signature(node) == signature
|
||||
|
||||
|
||||
def test_parser_cache_clear(Script):
|
||||
"""
|
||||
If parso clears its cache, Jedi should not keep those resources, they
|
||||
should be freed.
|
||||
"""
|
||||
script = Script("a = abs\na", path=Path(__file__).parent / 'parser_cache_test_foo.py')
|
||||
script.complete()
|
||||
module_id = id(script._module_node)
|
||||
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)]
|
||||
|
||||
Reference in New Issue
Block a user