clean up caches clearing

This commit is contained in:
Dave Halter
2013-12-26 02:10:30 +01:00
parent 947e616da0
commit 8f564a301f
4 changed files with 9 additions and 24 deletions

View File

@@ -82,7 +82,7 @@ class Script(object):
if not (0 <= self._column <= line_len):
raise ValueError('`column` parameter is not in a valid range.')
#api_classes._clear_caches() # TODO REMOVE
api_classes.clear_caches()
debug.reset_time()
self.source = modules.source_to_unicode(source, encoding)
self._pos = self._line, self._column
@@ -111,7 +111,6 @@ class Script(object):
""" lazy parser."""
return self._module.parser
#@api_classes._clear_caches_after_call
def completions(self):
"""
Return :class:`api_classes.Completion` objects. Those objects contain
@@ -319,7 +318,6 @@ class Script(object):
sig = self.call_signatures()
return sig[0] if sig else None
#@api_classes._clear_caches_after_call
def goto_definitions(self):
"""
Return the definitions of a the path under the cursor. goto function!
@@ -383,7 +381,6 @@ class Script(object):
if s is not imports.ImportPath.GlobalNamespace])
return self._sorted_defs(d)
#@api_classes._clear_caches_after_call
def goto_assignments(self):
"""
Return the first definition found. Imports and statements aren't
@@ -453,7 +450,6 @@ class Script(object):
definitions = [user_stmt]
return definitions, search_name
#@api_classes._clear_caches_after_call
def usages(self, additional_module_paths=()):
"""
Return :class:`api_classes.Usage` objects, which contain all
@@ -477,8 +473,7 @@ class Script(object):
if unicode(v.names[-1]) == search_name]
if not isinstance(user_stmt, pr.Import):
# import case is looked at with add_import_name option
definitions = dynamic.usages_add_import_modules(definitions,
search_name)
definitions = usages_add_import_modules(self._evaluator, definitions, search_name)
module = set([d.get_parent_until() for d in definitions])
module.add(self._parser.module)
@@ -497,7 +492,6 @@ class Script(object):
settings.dynamic_flow_information = temp
return self._sorted_defs(set(names))
#@api_classes._clear_caches_after_call
def call_signatures(self):
"""
Return the function object of the call you're currently in.
@@ -725,7 +719,7 @@ def usages(evaluator, definitions, search_name, mods):
for f in follow:
follow_res, search = evaluator.goto(call.parent, f)
follow_res = usages_add_import_modules(follow_res, search)
follow_res = usages_add_import_modules(evaluator, follow_res, search)
compare_follow_res = compare_array(follow_res)
# compare to see if they match

View File

@@ -17,18 +17,13 @@ from jedi import keywords
from jedi.evaluate import dynamic
def _clear_caches():
def clear_caches():
"""
Clear all caches of this and related modules. The only cache that will not
be deleted is the module cache.
"""
cache.clear_caches()
dynamic.search_param_cache.clear()
recursion.ExecutionRecursionDecorator.reset()
evaluate.follow_statement.reset()
imports.imports_processed = 0
def _clear_caches_after_call(func):
@@ -38,7 +33,7 @@ def _clear_caches_after_call(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
result = func(*args, **kwds)
_clear_caches()
clear_caches()
return result
return wrapper
@@ -416,7 +411,7 @@ class Completion(BaseDefinition):
self._followed_definitions = \
[BaseDefinition(d, d.start_pos) for d in defs]
_clear_caches()
clear_caches()
return self._followed_definitions

View File

@@ -26,9 +26,6 @@ from jedi.parser import representation as pr
from jedi import cache
from jedi.evaluate import builtin
# for debugging purposes only
imports_processed = 0
class ModuleNotFound(Exception):
pass
@@ -304,8 +301,6 @@ class ImportPath(pr.Base):
elif self._is_relative_import():
path = self._get_relative_path()
global imports_processed
imports_processed += 1
if path is not None:
importing = find_module(string, [path])
else:

View File

@@ -11,9 +11,9 @@ import jedi
def test_is_keyword():
results = Script('import ', 1, 1, None).goto_definitions()
assert len(results) == 1 and results[0].is_keyword == True
assert len(results) == 1 and results[0].is_keyword is True
results = Script('str', 1, 1, None).goto_definitions()
assert len(results) == 1 and results[0].is_keyword == False
assert len(results) == 1 and results[0].is_keyword is False
def make_definitions():
"""
@@ -71,6 +71,7 @@ def test_function_call_signature_in_doc():
doc = defs[0].doc
assert "f(x, y = 1, z = 'a')" in doc
def test_class_call_signature():
defs = Script("""
class Foo: