mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-21 13:01:14 +08:00
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:
@@ -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:
|
||||||
|
|||||||
@@ -52,17 +52,24 @@ def search_params(evaluator, param):
|
|||||||
is.
|
is.
|
||||||
"""
|
"""
|
||||||
if not settings.dynamic_params:
|
if not settings.dynamic_params:
|
||||||
return []
|
return set()
|
||||||
|
|
||||||
func = param.get_parent_until(tree.Function)
|
if evaluator.dynamic_params_depth == settings.max_dynamic_params_depth:
|
||||||
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA')
|
return set()
|
||||||
# Compare the param names.
|
|
||||||
names = [n for n in search_function_call(evaluator, func)
|
evaluator.dynamic_params_depth += 1
|
||||||
if n.value == param.name.value]
|
try:
|
||||||
# Evaluate the ExecutedParams to types.
|
func = param.get_parent_until(tree.Function)
|
||||||
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
|
debug.dbg('Dynamic param search for %s in %s.', param, str(func.name), color='MAGENTA')
|
||||||
debug.dbg('Dynamic param result %s', result, color='MAGENTA')
|
# Compare the param names.
|
||||||
return result
|
names = [n for n in search_function_call(evaluator, func)
|
||||||
|
if n.value == param.name.value]
|
||||||
|
# Evaluate the ExecutedParams to types.
|
||||||
|
result = set(chain.from_iterable(n.parent.eval(evaluator) for n in names))
|
||||||
|
debug.dbg('Dynamic param result %s', result, color='MAGENTA')
|
||||||
|
return result
|
||||||
|
finally:
|
||||||
|
evaluator.dynamic_params_depth -= 1
|
||||||
|
|
||||||
|
|
||||||
@memoize_default([], evaluator_is_first_arg=True)
|
@memoize_default([], evaluator_is_first_arg=True)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user