1
0
forked from VimPlug/jedi

init decorators should not execute __init__ in case of self variable lookups, fixes #247

This commit is contained in:
David Halter
2013-08-10 22:55:58 +04:30
parent 6421c95df1
commit 959519560d

View File

@@ -72,7 +72,7 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
self.is_generated = False self.is_generated = False
@cache.memoize_default() @cache.memoize_default()
def _get_init_execution(self, func): def _get_method_execution(self, func):
func = InstanceElement(self, func, True) func = InstanceElement(self, func, True)
return Execution(func, self.var_args) return Execution(func, self.var_args)
@@ -105,10 +105,17 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
continue continue
# Get the self name, if there's one. # Get the self name, if there's one.
self_name = self._get_func_self_name(sub) self_name = self._get_func_self_name(sub)
if self_name: if not self_name:
# Check the __init__ function. continue
if sub.name.get_code() == '__init__': if sub.name.get_code() == '__init__':
sub = self._get_init_execution(sub) # ``__init__`` is special because the params need are injected
# this way. Therefore an execution is necessary.
if not sub.decorators:
# __init__ decorators should generally just be ignored,
# because to follow them and their self variables is too
# complicated.
sub = self._get_method_execution(sub)
for n in sub.get_set_vars(): for n in sub.get_set_vars():
# Only names with the selfname are being added. # Only names with the selfname are being added.
# It is also important, that they have a len() of 2, # It is also important, that they have a len() of 2,
@@ -213,7 +220,6 @@ class InstanceElement(use_metaclass(cache.CachedMetaClass, pr.Base)):
def get_decorated_func(self): def get_decorated_func(self):
""" Needed because the InstanceElement should not be stripped """ """ Needed because the InstanceElement should not be stripped """
#print 'gdf', self, self.is_decorated
func = self.var.get_decorated_func(self.instance) func = self.var.get_decorated_func(self.instance)
if func == self.var: if func == self.var:
return self return self