1
0
forked from VimPlug/jedi

Add a max_dynamic_params_depth setting to limit recusive searching for those params. It shouldn't be too crazy.

This commit is contained in:
Dave Halter
2016-07-17 13:59:19 +02:00
parent 218278af8d
commit 75c1ebc2fe
5 changed files with 35 additions and 11 deletions

View File

@@ -89,6 +89,7 @@ class Evaluator(object):
self.mixed_cache = {} # see `evaluate.compiled.mixed.create()` self.mixed_cache = {} # see `evaluate.compiled.mixed.create()`
self.analysis = [] self.analysis = []
self.predefined_if_name_dict_dict = {} self.predefined_if_name_dict_dict = {}
self.dynamic_params_depth = 0
self.is_analysis = False self.is_analysis = False
if sys_path is None: if sys_path is None:

View File

@@ -52,8 +52,13 @@ def search_params(evaluator, param):
is. is.
""" """
if not settings.dynamic_params: if not settings.dynamic_params:
return [] return set()
if evaluator.dynamic_params_depth == settings.max_dynamic_params_depth:
return set()
evaluator.dynamic_params_depth += 1
try:
func = param.get_parent_until(tree.Function) func = param.get_parent_until(tree.Function)
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA') debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA')
# Compare the param names. # Compare the param names.
@@ -63,6 +68,8 @@ def search_params(evaluator, param):
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names)) result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
debug.dbg('Dynamic param result %s', result, color='MAGENTA') debug.dbg('Dynamic param result %s', result, color='MAGENTA')
return result return result
finally:
evaluator.dynamic_params_depth -= 1
@memoize_default([], evaluator_is_first_arg=True) @memoize_default([], evaluator_is_first_arg=True)

View File

@@ -696,7 +696,7 @@ class FunctionExecution(Executed):
else: else:
yield self._evaluator.eval_element(element) yield self._evaluator.eval_element(element)
# TODO add execution_recursion_decorator?! @recursion.execution_recursion_decorator
def get_yield_types(self): def get_yield_types(self):
yields = self.yields yields = self.yields
stopAt = tree.ForStmt, tree.WhileStmt, FunctionExecution, tree.IfStmt stopAt = tree.ForStmt, tree.WhileStmt, FunctionExecution, tree.IfStmt

View File

@@ -63,6 +63,7 @@ definitely worse in some cases. But a completion should also be fast.
.. autodata:: max_function_recursion_level .. autodata:: max_function_recursion_level
.. autodata:: max_executions_without_builtins .. autodata:: max_executions_without_builtins
.. autodata:: max_executions .. autodata:: max_executions
.. autodata:: max_dynamic_params_depth
.. autodata:: scale_call_signatures .. autodata:: scale_call_signatures
@@ -207,6 +208,12 @@ max_executions = 250
A maximum amount of time, the completion may use. A maximum amount of time, the completion may use.
""" """
max_dynamic_params_depth = 3
"""
A maximum amount of a recursive search function calls, when the type of a
parameter is needed.
"""
scale_call_signatures = 0.1 scale_call_signatures = 0.1
""" """
Because call_signatures is normally used on every single key hit, it has Because call_signatures is normally used on every single key hit, it has

View File

@@ -212,3 +212,12 @@ class B(object):
cls = random.choice([A, B]) cls = random.choice([A, B])
#? ['say', 'shout'] #? ['say', 'shout']
cls().s cls().s
# -----------------
# random
# -----------------
import zipfile
z = zipfile.ZipFile("foo")
#? ['upper']
z.read('name').upper