mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-22 03:42:05 +08:00
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:
@@ -7,6 +7,7 @@ interesting information about completion and goto operations.
|
||||
import re
|
||||
import os
|
||||
import warnings
|
||||
import functools
|
||||
|
||||
from _compatibility import unicode, next
|
||||
import cache
|
||||
@@ -34,6 +35,18 @@ def _clear_caches():
|
||||
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):
|
||||
_mapping = {'posixpath': 'os.path',
|
||||
'riscospath': 'os.path',
|
||||
|
||||
Reference in New Issue
Block a user