From 68ff520cf8e5c3907312759d5730acc22913ecee Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 17 Jul 2016 19:49:12 +0200 Subject: [PATCH] Limit dynamic param searches to not go crazy in a lot of occasions. Refs #574. --- jedi/evaluate/dynamic.py | 12 +++++++++--- jedi/settings.py | 6 ------ test/completion/stdlib.py | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/jedi/evaluate/dynamic.py b/jedi/evaluate/dynamic.py index 0f8f9b09..30ef27a8 100644 --- a/jedi/evaluate/dynamic.py +++ b/jedi/evaluate/dynamic.py @@ -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: diff --git a/jedi/settings.py b/jedi/settings.py index 45360ac9..13dcfd45 100644 --- a/jedi/settings.py +++ b/jedi/settings.py @@ -208,12 +208,6 @@ max_executions = 250 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 """ Because call_signatures is normally used on every single key hit, it has diff --git a/test/completion/stdlib.py b/test/completion/stdlib.py index 88f3cfed..92b7929a 100644 --- a/test/completion/stdlib.py +++ b/test/completion/stdlib.py @@ -219,5 +219,6 @@ cls().s import zipfile z = zipfile.ZipFile("foo") -#? ['upper'] +# It's too slow. So we don't run it at the moment. +##? ['upper'] z.read('name').upper