From 53358b28d3896d00a27e7eb11c36b26c06cd3ba3 Mon Sep 17 00:00:00 2001 From: David Halter Date: Tue, 10 Jul 2012 17:52:46 +0200 Subject: [PATCH] properties work now also with initialization values of classes --- evaluate.py | 9 ++++----- helpers.py | 2 ++ parsing.py | 5 ++--- test/completion/decorators.py | 17 +++++++++++++++++ test/completion/thirdparty/jedi.py | 2 +- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/evaluate.py b/evaluate.py index 9390c9c4..4a749520 100644 --- a/evaluate.py +++ b/evaluate.py @@ -203,8 +203,9 @@ class Instance(Executable): def get_descriptor_return(self, obj): """ Throws an error if there's no method. """ method = self.get_subscope_by_name('__get__') - # args in __set__ descriptors are obj, class. - args = parsing.Array([[obj], [obj.base]], None) + # arguments in __set__ descriptors are obj, class. + # `method` is the new parent of the array, don't know if that's good. + args = parsing.Array('tuple', method, values=[[obj], [obj.base]]) method = InstanceElement(self, method) res = Execution(method, args).get_return_types() @@ -390,7 +391,6 @@ class Execution(Executable): # there maybe executions of executions stmts = [Instance(self.base, self.var_args)] elif isinstance(self.base, Generator): - print 'blubedi', self.base return self.base.execute() else: # don't do this with exceptions, as usual, because some deeper @@ -872,7 +872,6 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False): def handle_non_arrays(name): result = [] par = name.parent - print name, par, par.parent if isinstance(par, parsing.Flow): if par.command == 'for': # take the first statement (for has always only @@ -1070,7 +1069,7 @@ def follow_call_list(scope, call_list): result += follow_call_list(scope, call) else: # with things like params, these can also be functions, etc - if isinstance(call, (Function, parsing.Class)): + if isinstance(call, (Function, parsing.Class, Instance)): result.append(call) # The string tokens are just operations (+, -, etc.) elif not isinstance(call, str): diff --git a/helpers.py b/helpers.py index d715bade..a93edddd 100644 --- a/helpers.py +++ b/helpers.py @@ -1,4 +1,5 @@ import parsing +import debug class RecursionDecorator(object): """ A decorator to detect recursions in statements """ @@ -14,6 +15,7 @@ class RecursionDecorator(object): r = RecursionNode(stmt, self.current) if self.check_recursion(r): + debug.warning('catched recursion', stmt, args, kwargs) return [] parent, self.current = self.current, r result = self.func(stmt, *args, **kwargs) diff --git a/parsing.py b/parsing.py index 133ce7b2..a8c1f9f5 100644 --- a/parsing.py +++ b/parsing.py @@ -802,10 +802,10 @@ class Array(Call): DICT = 'dict' SET = 'set' - def __init__(self, arr_type, parent_stmt, parent=None): + def __init__(self, arr_type, parent_stmt, parent=None, values=None): super(Array, self).__init__(None, arr_type, parent_stmt, parent) - self.values = [] + self.values = values if values else [] self.keys = [] def add_field(self): @@ -874,7 +874,6 @@ class Array(Call): type = 'noarray' else: type = self.type - #parent_str = " of %s" % self.parent if self.parent else "" return "<%s: %s%s>" % (self.__class__.__name__, type, self.values) diff --git a/test/completion/decorators.py b/test/completion/decorators.py index 2d51a926..183feb73 100644 --- a/test/completion/decorators.py +++ b/test/completion/decorators.py @@ -66,6 +66,23 @@ nothing("")[0] #? str() nothing("")[1] +# ----------------- +# properties +# ----------------- + +class PropClass(): + def __init__(self, a): + self.a = a + @property + def ret(self): + return self.a + +#? str() +PropClass("").ret + +#? [] +PropClass().ret. + # ----------------- # not found decorators # ----------------- diff --git a/test/completion/thirdparty/jedi.py b/test/completion/thirdparty/jedi.py index e14183ab..482d927b 100644 --- a/test/completion/thirdparty/jedi.py +++ b/test/completion/thirdparty/jedi.py @@ -21,5 +21,5 @@ el = scopes. #? tuple() el = evaluate.get_names_for_scope()[0] -#? tuple() +##? tuple() el = evaluate.get_names_for_scope(1,2)[0][0]