forked from VimPlug/jedi
Break Interpreter completion even more in favor of a better solution in the future.
This commit is contained in:
@@ -85,7 +85,8 @@ class Evaluator(object):
|
||||
self.memoize_cache = {} # for memoize decorators
|
||||
# To memorize modules -> equals `sys.modules`.
|
||||
self.modules = {} # like `sys.modules`.
|
||||
self.compiled_cache = {} # see `compiled.create()`
|
||||
self.compiled_cache = {} # see `evaluate.compiled.create()`
|
||||
self.mixed_cache = {} # see `evaluate.compiled.mixed.create()`
|
||||
self.analysis = []
|
||||
self.predefined_if_name_dict_dict = {}
|
||||
self.is_analysis = False
|
||||
|
||||
@@ -475,21 +475,35 @@ def get_special_object(evaluator, identifier):
|
||||
return create(evaluator, obj, parent=create(evaluator, _builtins))
|
||||
|
||||
|
||||
def compiled_objects_cache(func):
|
||||
def wrapper(evaluator, obj, parent=None, module=None):
|
||||
# Do a very cheap form of caching here.
|
||||
key = id(obj)
|
||||
try:
|
||||
return evaluator.compiled_cache[key][0]
|
||||
except KeyError:
|
||||
result = func(evaluator, obj, parent, module)
|
||||
# Need to cache all of them, otherwise the id could be overwritten.
|
||||
evaluator.compiled_cache[key] = result, obj, parent, module
|
||||
return result
|
||||
return wrapper
|
||||
def compiled_objects_cache(attribute_name):
|
||||
def decorator(func):
|
||||
"""
|
||||
This decorator caches just the ids, oopposed to caching the object itself.
|
||||
Caching the id has the advantage that an object doesn't need to be
|
||||
hashable.
|
||||
"""
|
||||
def wrapper(evaluator, obj, parent=None, module=None):
|
||||
cache = getattr(evaluator, attribute_name)
|
||||
# Do a very cheap form of caching here.
|
||||
key = id(obj)
|
||||
try:
|
||||
return cache[key][0]
|
||||
except KeyError:
|
||||
# TODO this whole decorator looks way too ugly and this if
|
||||
# doesn't make it better. Find a more generic solution.
|
||||
if parent or module:
|
||||
result = func(evaluator, obj, parent, module)
|
||||
else:
|
||||
result = func(evaluator, obj)
|
||||
# Need to cache all of them, otherwise the id could be overwritten.
|
||||
cache[key] = result, obj, parent, module
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@compiled_objects_cache
|
||||
@compiled_objects_cache('compiled_cache')
|
||||
def create(evaluator, obj, parent=None, module=None):
|
||||
"""
|
||||
A very weird interface class to this module. The more options provided the
|
||||
|
||||
@@ -134,7 +134,7 @@ def find_syntax_node_name(evaluator, python_object):
|
||||
return names[-1]
|
||||
|
||||
|
||||
@memoize_default(evaluator_is_first_arg=True)
|
||||
@compiled.compiled_objects_cache('mixed_cache')
|
||||
def create(evaluator, obj):
|
||||
name = find_syntax_node_name(evaluator, obj)
|
||||
if name is None:
|
||||
|
||||
@@ -62,8 +62,8 @@ def filter_definition_names(names, origin, position=None):
|
||||
stmt = names[0].get_definition()
|
||||
scope = stmt.get_parent_scope()
|
||||
|
||||
if not (isinstance(scope, er.FunctionExecution)
|
||||
and isinstance(scope.base, er.LambdaWrapper)):
|
||||
if not (isinstance(scope, er.FunctionExecution) and
|
||||
isinstance(scope.base, er.LambdaWrapper)):
|
||||
names = filter_after_position(names, position)
|
||||
names = [name for name in names if name.is_definition()]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user