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:
Takafumi Arakaki
2013-03-15 00:21:46 +01:00
parent 22fa66b6e1
commit 7cf70a3f0a
2 changed files with 18 additions and 3 deletions

View File

@@ -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',