From 4cd1efc5ba67fe752d1e6b0581225099ee6f3dd2 Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 19 Jul 2012 18:29:04 +0200 Subject: [PATCH] descriptors are now also working with classes. this means classmethod/staticmethod are now working --- evaluate.py | 9 ++++++--- mixin/builtins.py | 2 +- test/completion/classes.py | 26 +++++++++++++++----------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/evaluate.py b/evaluate.py index 2ab7fc64..5847d6bb 100644 --- a/evaluate.py +++ b/evaluate.py @@ -558,8 +558,11 @@ class Execution(Executable): def iterate(): # `var_args` is typically an Array, and not a list. for var_arg in self.var_args: + # empty var_arg + if len(var_arg) == 0: + yield None, None # *args - if var_arg[0] == '*': + elif var_arg[0] == '*': arrays = follow_call_list([var_arg[1:]]) for array in arrays: for field in array.get_contents(): @@ -958,7 +961,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False): res_new = [] #print 'descc', scope, result, name_str for r in result: - if isinstance(scope, (Instance)) \ + if isinstance(scope, (Instance, Class)) \ and hasattr(r, 'get_descriptor_return'): # handle descriptors try: @@ -1079,7 +1082,7 @@ def follow_call_list(call_list): result += follow_call_list(call) else: # With things like params, these can also be functions... - if isinstance(call, (Function, parsing.Class, Instance)): + if isinstance(call, (Function, Class, Instance)): result.append(call) # The string tokens are just operations (+, -, etc.) elif not isinstance(call, str): diff --git a/mixin/builtins.py b/mixin/builtins.py index b46d4596..38979489 100644 --- a/mixin/builtins.py +++ b/mixin/builtins.py @@ -47,5 +47,5 @@ class classmethod(): def __get__(self, obj, cls): def _method(*args, **kwargs): - self._func(cls, *args, **kwargs) + return self._func(cls, *args, **kwargs) return _method diff --git a/test/completion/classes.py b/test/completion/classes.py index 850a4531..8347793b 100644 --- a/test/completion/classes.py +++ b/test/completion/classes.py @@ -236,6 +236,10 @@ class RevealAccess(object): class C(object): x = RevealAccess(10, 'var "x"') + #? RevealAccess() + x + #? ['__get__'] + x.__get__ y = 5.0 m = C() @@ -243,7 +247,7 @@ m = C() m.x #? float() m.y -##? int() +#? int() C.x # ----------------- @@ -335,25 +339,25 @@ class E(object): return cls.a e = E(1) -##? int() +#? int() e.f(1) -##? int() +#? int() E.f(1) -##? int() +#? int() e.g(1) -##? int() +#? int() E.g(1) -##? int() +#? int() e.s(1) -##? int() +#? int() E.s(1) -##? int() +#? int() e.t(1) -##? int() +#? int() E.t(1) -##? str() +#? str() e.u(1) -##? str() +#? str() E.u(1)