Limit dynamic param searches to not go crazy in a lot of occasions. Refs #574.

This commit is contained in:
Dave Halter
2016-07-17 19:49:12 +02:00
parent becbbb2e64
commit 68ff520cf8
3 changed files with 11 additions and 10 deletions

View File

@@ -26,6 +26,9 @@ from jedi.evaluate.cache import memoize_default
from jedi.evaluate import imports
MAX_PARAM_SEARCHES = 10
class ParamListener(object):
"""
This listener is used to get the params for a function.
@@ -54,9 +57,6 @@ def search_params(evaluator, param):
if not settings.dynamic_params:
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)
@@ -123,6 +123,12 @@ def search_function_call(evaluator, func):
for name, trailer in get_possible_nodes(mod, func_name):
i += 1
# This is a simple way to stop Jedi's dynamic param recursion
# from going wild: The deeper Jedi's in the recursin, the less
# code should be evaluated.
if i * evaluator.dynamic_params_depth > MAX_PARAM_SEARCHES:
return listener.param_possibilities
for typ in evaluator.goto_definitions(name):
undecorated = undecorate(typ)
if evaluator.wrap(compare) == undecorated: