mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
clean up caches clearing
This commit is contained in:
12
jedi/api.py
12
jedi/api.py
@@ -82,7 +82,7 @@ class Script(object):
|
|||||||
if not (0 <= self._column <= line_len):
|
if not (0 <= self._column <= line_len):
|
||||||
raise ValueError('`column` parameter is not in a valid range.')
|
raise ValueError('`column` parameter is not in a valid range.')
|
||||||
|
|
||||||
#api_classes._clear_caches() # TODO REMOVE
|
api_classes.clear_caches()
|
||||||
debug.reset_time()
|
debug.reset_time()
|
||||||
self.source = modules.source_to_unicode(source, encoding)
|
self.source = modules.source_to_unicode(source, encoding)
|
||||||
self._pos = self._line, self._column
|
self._pos = self._line, self._column
|
||||||
@@ -111,7 +111,6 @@ class Script(object):
|
|||||||
""" lazy parser."""
|
""" lazy parser."""
|
||||||
return self._module.parser
|
return self._module.parser
|
||||||
|
|
||||||
#@api_classes._clear_caches_after_call
|
|
||||||
def completions(self):
|
def completions(self):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Completion` objects. Those objects contain
|
Return :class:`api_classes.Completion` objects. Those objects contain
|
||||||
@@ -319,7 +318,6 @@ class Script(object):
|
|||||||
sig = self.call_signatures()
|
sig = self.call_signatures()
|
||||||
return sig[0] if sig else None
|
return sig[0] if sig else None
|
||||||
|
|
||||||
#@api_classes._clear_caches_after_call
|
|
||||||
def goto_definitions(self):
|
def goto_definitions(self):
|
||||||
"""
|
"""
|
||||||
Return the definitions of a the path under the cursor. goto function!
|
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])
|
if s is not imports.ImportPath.GlobalNamespace])
|
||||||
return self._sorted_defs(d)
|
return self._sorted_defs(d)
|
||||||
|
|
||||||
#@api_classes._clear_caches_after_call
|
|
||||||
def goto_assignments(self):
|
def goto_assignments(self):
|
||||||
"""
|
"""
|
||||||
Return the first definition found. Imports and statements aren't
|
Return the first definition found. Imports and statements aren't
|
||||||
@@ -453,7 +450,6 @@ class Script(object):
|
|||||||
definitions = [user_stmt]
|
definitions = [user_stmt]
|
||||||
return definitions, search_name
|
return definitions, search_name
|
||||||
|
|
||||||
#@api_classes._clear_caches_after_call
|
|
||||||
def usages(self, additional_module_paths=()):
|
def usages(self, additional_module_paths=()):
|
||||||
"""
|
"""
|
||||||
Return :class:`api_classes.Usage` objects, which contain all
|
Return :class:`api_classes.Usage` objects, which contain all
|
||||||
@@ -477,8 +473,7 @@ class Script(object):
|
|||||||
if unicode(v.names[-1]) == search_name]
|
if unicode(v.names[-1]) == search_name]
|
||||||
if not isinstance(user_stmt, pr.Import):
|
if not isinstance(user_stmt, pr.Import):
|
||||||
# import case is looked at with add_import_name option
|
# import case is looked at with add_import_name option
|
||||||
definitions = dynamic.usages_add_import_modules(definitions,
|
definitions = usages_add_import_modules(self._evaluator, definitions, search_name)
|
||||||
search_name)
|
|
||||||
|
|
||||||
module = set([d.get_parent_until() for d in definitions])
|
module = set([d.get_parent_until() for d in definitions])
|
||||||
module.add(self._parser.module)
|
module.add(self._parser.module)
|
||||||
@@ -497,7 +492,6 @@ class Script(object):
|
|||||||
settings.dynamic_flow_information = temp
|
settings.dynamic_flow_information = temp
|
||||||
return self._sorted_defs(set(names))
|
return self._sorted_defs(set(names))
|
||||||
|
|
||||||
#@api_classes._clear_caches_after_call
|
|
||||||
def call_signatures(self):
|
def call_signatures(self):
|
||||||
"""
|
"""
|
||||||
Return the function object of the call you're currently in.
|
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:
|
for f in follow:
|
||||||
follow_res, search = evaluator.goto(call.parent, f)
|
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_follow_res = compare_array(follow_res)
|
||||||
# compare to see if they match
|
# compare to see if they match
|
||||||
|
|||||||
@@ -17,18 +17,13 @@ from jedi import keywords
|
|||||||
from jedi.evaluate import dynamic
|
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
|
Clear all caches of this and related modules. The only cache that will not
|
||||||
be deleted is the module cache.
|
be deleted is the module cache.
|
||||||
"""
|
"""
|
||||||
cache.clear_caches()
|
cache.clear_caches()
|
||||||
dynamic.search_param_cache.clear()
|
dynamic.search_param_cache.clear()
|
||||||
recursion.ExecutionRecursionDecorator.reset()
|
|
||||||
|
|
||||||
evaluate.follow_statement.reset()
|
|
||||||
|
|
||||||
imports.imports_processed = 0
|
|
||||||
|
|
||||||
|
|
||||||
def _clear_caches_after_call(func):
|
def _clear_caches_after_call(func):
|
||||||
@@ -38,7 +33,7 @@ def _clear_caches_after_call(func):
|
|||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwds):
|
def wrapper(*args, **kwds):
|
||||||
result = func(*args, **kwds)
|
result = func(*args, **kwds)
|
||||||
_clear_caches()
|
clear_caches()
|
||||||
return result
|
return result
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@@ -416,7 +411,7 @@ class Completion(BaseDefinition):
|
|||||||
|
|
||||||
self._followed_definitions = \
|
self._followed_definitions = \
|
||||||
[BaseDefinition(d, d.start_pos) for d in defs]
|
[BaseDefinition(d, d.start_pos) for d in defs]
|
||||||
_clear_caches()
|
clear_caches()
|
||||||
|
|
||||||
return self._followed_definitions
|
return self._followed_definitions
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ from jedi.parser import representation as pr
|
|||||||
from jedi import cache
|
from jedi import cache
|
||||||
from jedi.evaluate import builtin
|
from jedi.evaluate import builtin
|
||||||
|
|
||||||
# for debugging purposes only
|
|
||||||
imports_processed = 0
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleNotFound(Exception):
|
class ModuleNotFound(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -304,8 +301,6 @@ class ImportPath(pr.Base):
|
|||||||
elif self._is_relative_import():
|
elif self._is_relative_import():
|
||||||
path = self._get_relative_path()
|
path = self._get_relative_path()
|
||||||
|
|
||||||
global imports_processed
|
|
||||||
imports_processed += 1
|
|
||||||
if path is not None:
|
if path is not None:
|
||||||
importing = find_module(string, [path])
|
importing = find_module(string, [path])
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import jedi
|
|||||||
|
|
||||||
def test_is_keyword():
|
def test_is_keyword():
|
||||||
results = Script('import ', 1, 1, None).goto_definitions()
|
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()
|
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():
|
def make_definitions():
|
||||||
"""
|
"""
|
||||||
@@ -71,6 +71,7 @@ def test_function_call_signature_in_doc():
|
|||||||
doc = defs[0].doc
|
doc = defs[0].doc
|
||||||
assert "f(x, y = 1, z = 'a')" in doc
|
assert "f(x, y = 1, z = 'a')" in doc
|
||||||
|
|
||||||
|
|
||||||
def test_class_call_signature():
|
def test_class_call_signature():
|
||||||
defs = Script("""
|
defs = Script("""
|
||||||
class Foo:
|
class Foo:
|
||||||
|
|||||||
Reference in New Issue
Block a user