changed decorated func definitively, which makes things a little less complicated

This commit is contained in:
David Halter
2012-07-19 11:41:02 +02:00
parent 942cff225b
commit e90a073edd

View File

@@ -335,7 +335,7 @@ class Function(object):
@property @property
@memoize_default() @memoize_default()
def decorated_func(self): def _decorated_func(self):
""" """
Returns the function, that is to be executed in the end. Returns the function, that is to be executed in the end.
This is also the places where the decorators are processed. This is also the places where the decorators are processed.
@@ -378,25 +378,25 @@ class Function(object):
return f return f
def get_decorated_func(self): def get_decorated_func(self):
if self.decorated_func == None: if self._decorated_func == None:
raise DecoratorNotFound('Accessed returns in function') raise DecoratorNotFound('Accessed returns in function')
if self.decorated_func == self.base_func: if self._decorated_func == self.base_func:
return self return self
return self.decorated_func return self._decorated_func
def __getattr__(self, name): def __getattr__(self, name):
if name in ['get_defined_names', 'returns', 'params', 'statements', if name in ['get_defined_names', 'returns', 'params', 'statements',
'subscopes', 'imports', 'name', 'is_generator', 'subscopes', 'imports', 'name', 'is_generator',
'get_parent_until']: 'get_parent_until']:
return getattr(self.decorated_func, name) return getattr(self._decorated_func, name)
if name not in ['start_pos', 'end_pos', 'parent']: if name not in ['start_pos', 'end_pos', 'parent']:
raise AttributeError('Accessed name "%s" in function.' % name) raise AttributeError('Accessed name "%s" in function.' % name)
return getattr(self.base_func, name) return getattr(self.base_func, name)
def __repr__(self): def __repr__(self):
dec = '' dec = ''
if self.decorated_func != self.base_func: if self._decorated_func != self.base_func:
dec = " is " + repr(self.decorated_func) dec = " is " + repr(self._decorated_func)
return "<e%s of %s%s>" % (self.__class__.__name__, self.base_func, dec) return "<e%s of %s%s>" % (self.__class__.__name__, self.base_func, dec)
@@ -435,8 +435,6 @@ class Execution(Executable):
else: else:
debug.dbg('__call__', call_method, self.base) debug.dbg('__call__', call_method, self.base)
base = self.base base = self.base
if isinstance(self.base, Function):
base = self.base.decorated_func
call_method = InstanceElement(base, call_method) call_method = InstanceElement(base, call_method)
exe = Execution(call_method, self.var_args) exe = Execution(call_method, self.var_args)
stmts = exe.get_return_types() stmts = exe.get_return_types()
@@ -805,10 +803,8 @@ def get_defined_names_for_position(obj, position=None, start_scope=None):
names = obj.get_defined_names() names = obj.get_defined_names()
# Instances have special rules, always return all the possible completions, # Instances have special rules, always return all the possible completions,
# because class variables are always valid and the `self.` variables, too. # because class variables are always valid and the `self.` variables, too.
if not position or isinstance(obj, Instance) or isinstance(obj, Function) \ if not position or isinstance(obj, Instance) or start_scope != obj \
and isinstance(obj.decorated_func, Instance) \ and isinstance(start_scope, (parsing.Function, Execution)):
or start_scope != obj and isinstance(start_scope,
(parsing.Function, Execution)):
return names return names
names_new = [] names_new = []
for n in names: for n in names:
@@ -1186,8 +1182,7 @@ def follow_path(path, scope, position=None):
debug.warning('strange function call with {}', current, scope) debug.warning('strange function call with {}', current, scope)
else: else:
# The function must not be decorated with something else. # The function must not be decorated with something else.
if isinstance(scope, Function) and \ if isinstance(scope, Function):
isinstance(scope.decorated_func, Function):
# TODO Check default function methods and return them. # TODO Check default function methods and return them.
result = [] result = []
else: else: