forked from VimPlug/jedi
Do not clear cache in __del__
Prior to this change, running
`py.test --assert=rewrite test/test_integration.py` fails with errors
due to:
```py
cls = <class 'jedi.recursion.ExecutionRecursionDecorator'>
@classmethod
def cleanup(cls):
> cls.parent_execution_funcs.pop()
E IndexError: pop from empty list
recursion.py:127: IndexError
```
Similar errors occurred in travis occasionally:
- https://travis-ci.org/davidhalter/jedi/jobs/5449831
- https://travis-ci.org/davidhalter/jedi/jobs/5512538
I think this is because GC calls __del__ at random point during
actual execution of ExecutionRecursionDecorator.__call__.
As --assert=rewrite works by AST dynamically, I guess that it
is harder for Python's GC to clean up code and therefore GC
happens sometime later. Although this is just a random guess,
as `tox -- --assert=rewrite` works with this patch now, I think
this is a good change.
This commit is contained in:
@@ -76,6 +76,7 @@ class Script(object):
|
|||||||
""" lazy parser."""
|
""" lazy parser."""
|
||||||
return self._module.parser
|
return self._module.parser
|
||||||
|
|
||||||
|
@api_classes._clear_caches_after_call
|
||||||
def complete(self):
|
def complete(self):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Completion` objects. Those objects contain
|
Return :class:`api_classes.Completion` objects. Those objects contain
|
||||||
@@ -209,6 +210,7 @@ class Script(object):
|
|||||||
warnings.warn("Use line instead.", DeprecationWarning)
|
warnings.warn("Use line instead.", DeprecationWarning)
|
||||||
return self.definition()
|
return self.definition()
|
||||||
|
|
||||||
|
@api_classes._clear_caches_after_call
|
||||||
def definition(self):
|
def definition(self):
|
||||||
"""
|
"""
|
||||||
Return the definitions of a the path under the cursor. This is not a
|
Return the definitions of a the path under the cursor. This is not a
|
||||||
@@ -272,6 +274,7 @@ class Script(object):
|
|||||||
if not isinstance(s, imports.ImportPath._GlobalNamespace)])
|
if not isinstance(s, imports.ImportPath._GlobalNamespace)])
|
||||||
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
||||||
|
|
||||||
|
@api_classes._clear_caches_after_call
|
||||||
def goto(self):
|
def goto(self):
|
||||||
"""
|
"""
|
||||||
Return the first definition found by goto. Imports and statements
|
Return the first definition found by goto. Imports and statements
|
||||||
@@ -334,6 +337,7 @@ class Script(object):
|
|||||||
definitions = [user_stmt]
|
definitions = [user_stmt]
|
||||||
return definitions, search_name
|
return definitions, search_name
|
||||||
|
|
||||||
|
@api_classes._clear_caches_after_call
|
||||||
def related_names(self, additional_module_paths=()):
|
def related_names(self, additional_module_paths=()):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.RelatedName` objects, which contain all
|
Return :class:`api_classes.RelatedName` objects, which contain all
|
||||||
@@ -378,6 +382,7 @@ class Script(object):
|
|||||||
warnings.warn("Use line instead.", DeprecationWarning)
|
warnings.warn("Use line instead.", DeprecationWarning)
|
||||||
return self.function_definition()
|
return self.function_definition()
|
||||||
|
|
||||||
|
@api_classes._clear_caches_after_call
|
||||||
def function_definition(self):
|
def function_definition(self):
|
||||||
"""
|
"""
|
||||||
Return the function object of the call you're currently in.
|
Return the function object of the call you're currently in.
|
||||||
@@ -487,9 +492,6 @@ class Script(object):
|
|||||||
match = re.match(r'^(.*?)(\.|)(\w?[\w\d]*)$', path, flags=re.S)
|
match = re.match(r'^(.*?)(\.|)(\w?[\w\d]*)$', path, flags=re.S)
|
||||||
return match.groups()
|
return match.groups()
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
api_classes._clear_caches()
|
|
||||||
|
|
||||||
|
|
||||||
def defined_names(source, source_path=None, source_encoding='utf-8'):
|
def defined_names(source, source_path=None, source_encoding='utf-8'):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interesting information about completion and goto operations.
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
import functools
|
||||||
|
|
||||||
from _compatibility import unicode, next
|
from _compatibility import unicode, next
|
||||||
import cache
|
import cache
|
||||||
@@ -34,6 +35,18 @@ def _clear_caches():
|
|||||||
imports.imports_processed = 0
|
imports.imports_processed = 0
|
||||||
|
|
||||||
|
|
||||||
|
def _clear_caches_after_call(func):
|
||||||
|
"""
|
||||||
|
Clear caches just before returning a value.
|
||||||
|
"""
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapper(*args, **kwds):
|
||||||
|
result = func(*args, **kwds)
|
||||||
|
_clear_caches()
|
||||||
|
return result
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class BaseDefinition(object):
|
class BaseDefinition(object):
|
||||||
_mapping = {'posixpath': 'os.path',
|
_mapping = {'posixpath': 'os.path',
|
||||||
'riscospath': 'os.path',
|
'riscospath': 'os.path',
|
||||||
|
|||||||
Reference in New Issue
Block a user