From dd0cc343f85896875188cde8fe5dd5d41ae970c6 Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 30 Aug 2012 01:41:40 +0200 Subject: [PATCH] mainly settings documentation --- evaluate.py | 4 +++- helpers.py | 10 ++++------ settings.py | 28 +++++++++++++++++++++++++++- test/completion/thirdparty/jedi_.py | 6 +++++- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/evaluate.py b/evaluate.py index 943c610c..dc26c8b8 100644 --- a/evaluate.py +++ b/evaluate.py @@ -5,7 +5,6 @@ follow_statement -> follow_call -> follow_paths -> follow_path `get_names_for_scope` and `get_scopes_for_name` are search functions TODO doc -TODO list comprehensions, priority? +1 TODO magic methods: __mul__, __add__, etc. TODO evaluate asserts/isinstance (type safety) @@ -199,6 +198,9 @@ class Instance(Executable): add_self_dot_name(n) for s in self.base.get_super_classes(): + if s == self.base: + # I don't know how this could happen... But saw it once. + continue names += Instance(s).get_self_properties() return names diff --git a/helpers.py b/helpers.py index 71e01ebc..0d9f79df 100644 --- a/helpers.py +++ b/helpers.py @@ -88,11 +88,8 @@ class ExecutionRecursionDecorator(object): self.reset() def __call__(self, execution, evaluate_generator=False): - #print execution, self.recursion_level, self.execution_count, - #print len(self.execution_funcs), - a= self.check_recursion(execution, evaluate_generator) - #print a - if a: + #print execution, self.recursion_level, self.execution_count, len(self.execution_funcs), a + if self.check_recursion(execution, evaluate_generator): result = [] else: result = self.func(execution, evaluate_generator) @@ -162,8 +159,9 @@ def fast_parent_copy(obj): pass if hasattr(obj, 'parent_stmt') and obj.parent_stmt is not None: + p = obj.parent_stmt() try: - new_obj.parent_stmt = weakref.ref(new_elements[obj.parent_stmt()]) + new_obj.parent_stmt = weakref.ref(new_elements[p]) except KeyError: pass diff --git a/settings.py b/settings.py index 5babf6fa..8cb8cdf3 100644 --- a/settings.py +++ b/settings.py @@ -2,14 +2,40 @@ # dynamic stuff # ---------------- +# check for `append`, etc. on array instances like list() dynamic_arrays_instances = True +# check for `append`, etc. on arrays: [], {}, () dynamic_array_additions = True + +# A dynamic param completion, finds the callees of the function, which define +# the params of a function. dynamic_params = True # ---------------- # recursions # ---------------- +# Recursion settings are important if you don't want extremly recursive python +# code to go absolutely crazy. First of there is a global limit +# `max_executions`. This limit is important, to set a maximum amount of time, +# the completion may use. +# +# The `max_until_execution_unique` limit is probably the most important one, +# because if that limit is passed, functions can only be one time executed. So +# new functions will be executed, complex recursions with the same functions +# again and again, are ignored. +# +# `max_function_recursion_level` is more about whether the recursions are +# stopped in deepth or in width. The ratio beetween this and +# `max_until_execution_unique` is important here. It stops a recursion (after +# the number of function calls in the recursion), if it was already used +# earlier. +# +# The values are based on my experimental tries, used on the jedi library. But +# I don't think there's any other Python library, that uses recursion in a +# similar (extreme) way. This makes the completion definitely worse in some +# cases. But a completion should also be fast. + max_function_recursion_level = 5 max_until_execution_unique = 50 -max_executions = 5000 +max_executions = 1000 diff --git a/test/completion/thirdparty/jedi_.py b/test/completion/thirdparty/jedi_.py index 2ebce7bf..edb1a908 100644 --- a/test/completion/thirdparty/jedi_.py +++ b/test/completion/thirdparty/jedi_.py @@ -45,5 +45,9 @@ el = list(evaluate.get_names_for_scope())[0][1][0] #? evaluate.Array() evaluate.Class() evaluate.Function() evaluate.Instance() list(evaluate.follow_call())[0] -#? evaluate.Array() evaluate.Class() evaluate.Function() evaluate.Instance() +# With the right recursion settings, this should be possible (and maybe more): +# Array Class Function Generator Instance Module +# However, this was produced with the recursion settings 10/350/10000, and +# lasted 18.5 seconds. So we just have to be content with the results. +#? evaluate.Class() evaluate.Function() evaluate.get_scopes_for_name()[0]